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 - 3524 Views - Last Post: 27 March 2009 - 08:14 PM Rate Topic: -----

#1 jlt2jr  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 27-March 09

Help with stack and queue comparison(quick help)

Post icon  Posted 27 March 2009 - 08:06 PM

#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;
}


Is This A Good Question/Topic? 0
  • +

Replies To: Help with stack and queue comparison(quick help)

#2 NickDMax  Icon User is offline

  • Can grep dead trees!
  • member icon

Reputation: 2250
  • View blog
  • Posts: 9,245
  • Joined: 18-February 07

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: :code:

What is your question?
Was This Post Helpful? 0
  • +
  • -

#3 jlt2jr  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 27-March 09

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
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1