my code should check if the Entered string is a palindrome or not
// stack.h
typedef char comp;
struct nodetype;
typedef nodetype* nodeptr;
class stack{
public:
stack();
bool isfull()const;
bool isempty()const;
void push(comp elm);
void pop(comp& elm);
~stack();
private:
nodeptr top;
};
/********************************************
stack.cpp
*/
#include<iostream>
#include"stack.h"
#include<cstddef>
#include<cstdlib>
#include<cstring>
using namespace std;
struct nodetype
{
comp data;
nodeptr link;
};
stack::stack()
{
top=NULL;
}
bool stack::isempty()const
{
return top==NULL;
}
bool stack::isfull()const
{
nodeptr temp=new nodetype;
return temp==NULL;
}
void stack::push(comp elm)
{
if(isfull())
cout<<"No space ...!"<<endl;
else
{
nodeptr newptr=new nodetype;
newptr->data=elm;
newptr->link=top;
top=newptr;
}
}
void stack::pop(comp& elm)
{
if(isempty())
cout<<"NO DATA ...!"<<endl;
else
{
nodeptr del=top;
elm=top->data;
top=top->link;
delete del;
}
}
stack::~stack()
{
nodeptr del;
while(top!=NULL)
{
del=top;
top=top->link;
delete del;
}
}
/**********************************
client file
*/
#include<iostream>
#include"stack.h"
#include<cstring>
using namespace std;
int main()
{
char str[6];
char stcp[6];// to copy charachters from stack
char ch;
char ch2;// pop(ch2);
stack s1;//new OBJ of stack
cin.get(str,6);
int i=0;
while (str[i]!=NULL)
{
ch=str[i];
s1.push(ch);
i++;
}
for(int i=0;i<5;i++)
{
s1.pop(ch2);
stcp[i]=ch2;
}
int j=0;
bool ok=false;
while(stcp[j]!=NULL)
{
if(stcp[j]==str[j])
ok=true;
else
{
ok=false;
break;
}
j++;
}
if(ok)
cout<<"palindrome"<<endl;
else
cout<<"Not palindrome"<<endl;
system("pause");
return 0;
}
i think my proplem in char variable .....