C++ code checking palindrome … not working :s?
this specific code we have made down below runs nonetheless useless…any help! thanx
#include
#include
#define maxsize 100
int top=-1;
int front=-1;
int rear=-1;
char stackmaxsize;
char queuemaxsize;
bool isempty()
returning (top==-1rear==front);
bool isfull()
returning (top==maxsize-1rear==maxsize-1);
useless push (char x)
if(isfull())
cout<<"stack full"<<endl;
else
stack++top=x;
char pop()
if(isempty())
cout<<"stack empty"<<endl;
else
returning stacktop–;
useless enqueue(char x)
if(isfull())
cout<<"queue full"<<endl;
in addition queue++rear=x;
char dequeue()
in the event (isempty())
cout<<"queue empty"<<endl;
in addition return queue++front;
useless main()
int c=0;
char x;
cout<<"welcome….\n";
cout<<"enter r word to check out whether or not it is actually palindrome:";
cin.get(x);
even though (x! =’\n’)
push(x);
enqueue(x);
cin.get(x);
while(isempty()! =1)
if(pop()==dequeue())
c=1;
in the event (c==1)
cout<<"palindrome…";
in addition cout<<"not palindrome…";
getch();
it works for me maybe a little more detail on what exactly everyone looking for
ALTER:Ok, it’s because each occasion you call pop you’re subtracting through top and then when dequeue is named to examine isempty top are going to be equal to help -1 thus causing it to say queue can be empty.
Also your own logic can be wrong to determine if it really is palindrome struck! = tih but reported by your code it really is because stack1 = post and queue1 = when i therefore generating c = YOU.
Leave a Reply
You must be logged in to post a comment.