L
Lorin Leone
Can anyone help me modify the program so that it recognizes strings
like "Anna" as palindromes. To make the program "case-insensitive."
using the built-in C++ function "toupper". and so that it recognizes
strings like
"race car" as palindromes, have the program ignore spaces in the input
string.
Here is my code:
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
#include "Stack.h"
#include "queue.h"
int main()
{
Stack the_stack;
Queue the_queue;
char cur_char;
char tos;
char foq;
bool s;
bool is_pal;
cout << "input string: ";
cin.get(cur_char);
while (cur_char != '\n')
{
the_stack.push (cur_char));
the_queue.enqueue (cur_char);
cin.get (cur_char);
}
is_pal = true;
while(not the_queue.is_empty() and is_pal)
{
the_stack.get_top(tos, s);
the_queue.get_front(foq, s);
the_stack.pop(s);
the_queue.dequeue(s);
if(tos != foq)
is_pal = false;
}
cout << endl;
if( is_pal )
cout << "String is a palindrome." << endl;
else
cout << "String is NOT a palindrome." << endl;
return 0;
}
like "Anna" as palindromes. To make the program "case-insensitive."
using the built-in C++ function "toupper". and so that it recognizes
strings like
"race car" as palindromes, have the program ignore spaces in the input
string.
Here is my code:
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
#include "Stack.h"
#include "queue.h"
int main()
{
Stack the_stack;
Queue the_queue;
char cur_char;
char tos;
char foq;
bool s;
bool is_pal;
cout << "input string: ";
cin.get(cur_char);
while (cur_char != '\n')
{
the_stack.push (cur_char));
the_queue.enqueue (cur_char);
cin.get (cur_char);
}
is_pal = true;
while(not the_queue.is_empty() and is_pal)
{
the_stack.get_top(tos, s);
the_queue.get_front(foq, s);
the_stack.pop(s);
the_queue.dequeue(s);
if(tos != foq)
is_pal = false;
}
cout << endl;
if( is_pal )
cout << "String is a palindrome." << endl;
else
cout << "String is NOT a palindrome." << endl;
return 0;
}