#include <iostream>
#include <stack>
#include <queue>
#include <string>
#include <ctype.h>
using namespace std;
int main(){
char string1[20];
cout<<"Enter a word to determine whether or not it is a palindrome: \n";
cout<<"**limited to 1024 characters and do not use spaces and use the same case**\n";
cin>> string1;
cout<<endl;
stack<char> palindrome1;
queue<char> palindrome2;
int i = 0;
//insert input into the stack and queue
while (string1[i] != '\0'){
palindrome1.push(string1[i]);
palindrome2.push(string1[i]);
i++;
}
//print palindrome1 from the top
cout<<"STACK\n";
while (!palindrome1.empty()){
cout<<palindrome1.top();
palindrome1.pop();
}
cout<<"\n\n";
cout<<"QUEUE\n";
//print palindrome2 from the front
while (!palindrome2.empty()){
cout<<palindrome2.front();
palindrome2.pop();
}
cout<<"\n\n";
//NEED TO COMPARE Stack TO Queue TO CHECK EQUALITY
int f;
while(!palindrome1.empty() && !palindrome2.empty()){
f = 0;
if(palindrome1.top() != palindrome2.front()){
f++;
break;
}
palindrome1.pop();
palindrome2.pop();
}
cout<<f;
if (f>0)
cout<<"This word is a palindrome\n\n";
else
cout<<"This word is NOT a palindrome\n\n";
return 0;
}
Help with stack and queue comparison(quick help)everything works fine except the compare section at the bottom of the
Page 1 of 1
2 Replies - 2993 Views - Last Post: 27 March 2009 - 08:14 PM
#1
Help with stack and queue comparison(quick help)
Posted 27 March 2009 - 08:06 PM
Replies To: Help with stack and queue comparison(quick help)
#2
Re: Help with stack and queue comparison(quick help)
Posted 27 March 2009 - 08:10 PM
Moved and added code tags... Please post in the appropriate forum and use code tags: 
What is your question?
What is your question?
#3
Re: Help with stack and queue comparison(quick help)
Posted 27 March 2009 - 08:14 PM
i am trying to compare the characters in a stack to the character in a queue.
the point of the program is to detect whether a word is a palindrome
ex. mom
spelled the same even when it is reversed
the point of the program is to detect whether a word is a palindrome
ex. mom
spelled the same even when it is reversed
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote




|