-
Help
I am trying to determine if a string of characters is a palindrome or not by pushing each character onto a stack as it's read and simultaneously adding it to a queue. Here's is what I have so far.
#include <iostream.h>
#include <string.h>
#include "Stack.h"
#include "Queue.h"
int main()
{
Stack s1; // creat stack s1
Queue s2; // create queue s2
char s; // initialize s
cout << "Enter a string: "; // prompt user
cin >> s; // get from user
for(int i=0; i<=s.length(); i++) // count the string characters
{
s1.push(i); // push each character into stack
s2.addQ(i); // add each character into the queue
}
while(!s1.empty() && !s2.empty()) // check if stack and queue are empty
{
s1.pop(); // pop each character from stack
s2.addQ(); // puts characters in queue in reverse order
}
if(s1==s2) // check if the string is similar
cout <<"The string is palindrome";
else
cout <<"The string is not palindrome":
return 0;
}
Thanks for your precious time :~)
Popular pages
Recent additions