In: Computer Science
Write a function that uses a local char queue and a local char stack to determine if its string parameter is a palindrome. Your solution will look like:
#include <stack>
#include <queue>
...
bool isPalindrome(const string& candidate)
{
stack<char> s;
queue<char> q;
//add only upper case letters and digits to the stack and the queue
//if a letter is not upper case then convert it to upper case
}
Note: I need help to write out this problem in C++ while using Visual Studio 2017
#include<iostream>
#include<queue>
#include<stack>
#include <cctype>
using namespace std;
bool isPalindrome(const string& candidate)
{
   stack<char> s;
   queue<char> q;
   
   //add only upper case letters and digits to the stack and the queue
   //if a letter is not upper case then convert it to upper case  
   for(int i = 0;i<candidate.length();i++){
      if(isupper(candidate[i]) || isdigit(candidate[i])){
         s.push(candidate[i]);
         q.push(candidate[i]);
      }
      else if(islower(candidate[i])){
         s.push(toupper(candidate[i]));
         q.push(toupper(candidate[i]));
      }
   }
   while(!s.empty()){
      if(s.top() != q.front()){
         return false;
      }
      s.pop();
      q.pop();
   }
   return true;
}
int main() {
   //Testing isPalindrome function 
   cout<<isPalindrome("abcddcba")<<endl;
   cout<<isPalindrome("abcdcba")<<endl;
   cout<<isPalindrome("abdcba")<<endl;
   return 0;
}

1 1 0
