I have the following code that tests a string to see if it is a palindrome. The only error I am getting is when I try to pass each character to the queue and stack. Is there another way to pass it to each?

//Implement the palindrome-recognition algotithm described in "Simple Applications of the ADT Queue"

#include <iostream>
#include <queue>
#include <stack>
#include <string>


using namespace std;

void isPal(string);

void isPal(string s)
{
	queue <string> aQueue;		
	stack <string> aStack;	
	
	for(int i = 0; i < s.length(); i++)
	{	
	
		aQueue.push(s[i]);               //problem is right 
		aStack.push(s[i]);                // here
	}
	
	bool charEqual = true;
	
	while(!aQueue.empty() && charEqual ==true)
	{
		if(aQueue.front() == aStack.top())
		{

			aQueue.pop();
			aStack.pop();
		}
	}
	
	
//	return charEqual;
	
	if(charEqual == 0)
	{
		cout << "Yep its a palindrome" << endl;
	}
	
	else
		cout << "Nope, its not a palindrome" << endl;
	}

int main ()
{
	string input;
	cout << "Enter the string: ";
	cin >> input;
	isPal(input);

    return 0;
}

I have the following code that tests a string to see if it is a palindrome. The only error I am getting is when I try to pass each character to the queue and stack. Is there another way to pass it to each?

//Implement the palindrome-recognition algotithm described in "Simple Applications of the ADT Queue"

#include <iostream>
#include <queue>
#include <stack>
#include <string>


using namespace std;

void isPal(string);

void isPal(string s)
{
	queue <string> aQueue;		
	stack <string> aStack;	
	
	for(int i = 0; i < s.length(); i++)
	{	
	
		aQueue.push(s[i]);               //problem is right 
		aStack.push(s[i]);                // here
	}...

What's your actual error?

From what I can see the error is in your stack/queue declaration. You're adding charachters, not strings.

queue<char> aQueue;
stack<char> aStack;

//instead of

queue <string> aQueue;
stack <string> aStack;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.