-
palindrome trouble
I'm doing a data structure program where i write in a palidrome it puts it into a stack then into a queue then back to the stack and it also verifies that it is or isnt a palindrome what am i doing wrong
Code:
class Pali{
public:
Pali();
Pali(char str[]);
~Pali();
void instack();
void inqueue();
void outstack();
bool verify();
private:
stack<char>stackelems;
queue<char>queueelems;
stack<char>stackelems2;
CString char cstrelems[];}
Pali::Pali(){instack();};
Pali::Pali(char str[]){
strcpy(str,cstrelems);
instack();};
Pali::~Pali(){};
void Pali::instack(){
while(!stackelems.empty()){
cstrelems.push();}
inqueue();}
void Pali::inqueue(){
while(!queueelems.empty()){
stackelems.pop();
queueelems.push();}
outstack();}
void Pali::outstack(){
while(!stackelems2.empty()){
queueelems.pop();
stackelems2.push();}
if(verify()==true){
while(!stackelems2.empty()){
cout<<stackelems2.top();
stackelems2.pop();}
else{cout<<"This is not a palindrome!"<<endl;}}
cout<<"\n";}
bool Pali::verify(){
if((stackelems==stackelems2)==true){
return true;}
else
return false;
}
int main(){
char arr;
Pali sarr;
cout<<"Enter a palindrome: "<<endl;
cin>>arr;
sarr(arr);
return 0;}
-
Code:
int main()
{
char arr;
Pali sarr;
cout<<"Enter a palindrome: "<<endl;
cin>>arr;
sarr(arr);
return 0;
}
If you want to test whether something is a palindrome or not, you should allow the user to enter in more than a single character as input.
Do you really need all of this? The simplest way to check if something is a palindrome or not is to get the users input into a string variable, assign a second string as the reversed version of the input string, then do a compare of the two strings. This is only a few lines of code.
-
yes i do need all of this code it has to be a data structure use Stacks and Queues as i stated
whatelse am i doinng wrong