I'm reading a list of words that is terminated by $$$$$
madam
Madam I'm Adam.
A man, a plan, a canal, Panama!
Never odd or even
Amor, Roma
race car
step on NO pets
Able was I, ere I saw Elba
$$$$$
I want to get each line into a queue and stack to which I will compare if the top of the stack is the same as the front of the queue
1 2 3 4 5 6 7 8 9 10 11
if (s -> top < q -> front)
pal=-1;
elseif (s -> top > q -> front)
pal=1;
else pal=0;
s->top=s->top->next;
q->front=q->front->next;
if(pal==0)
cout<<words<<" - Is a palindrome"<<endl;
else
cout<<words<<" - Is not a palindrome"<<endl;
My issue is that I'm not properly getting the code to compare each line as I want it. I'm a student at this, and it is required that I use char, stacks and queues only.
std::basic_istream::getline() reads all the needed characters in a single operation: you may not want that instruction inside your 150-iterations for-loop.
To compare character by character your queue to your stack you don’t need that “int pal”: just stop at the first not matching character.
I think the exercise is about loading the *entire* read line inside a stack and inside a queue and after that comparing them character by character - since stack is a FILO structure and a queue is a FIFO one, that should become straightforward.
If you want to stuck to your code, I think you need to add two functions, one which pushes the entire line inside your stack and one inside your queue.
May I ask you, just out of curiosity, what type of course are you attending? Because your code is mostly C code, with just some C++ features.
first convert everything to all caps. strip out everything that's not a letter. compare that string to itself. way easier than writing the logic to compare something piecemeal on the unconverted string... If its required that you use certain features, you can use those features anyway, but still take the simplest approach ;-)