CODE
#include <iostream>
# include "queue.h"
#include <string>
#include "stack.h"
using namespace std;
int main()
{
queue Q;
stack S;
string str;
int i;
char ch;
cout<< "Enter a string: ";
getline(cin, str, '\n');;
for (i = 0; i < str.length(); i++)
{
ch = str [i];
Q.EnQueue(ch);
S.Push(ch);
}
while(!Empty() && charactersAreEqual)
{
Q.Front();
S.Top();
if(Q.Front ==S.Top)
{
Q.DeQueue();
S.Pop();
return true
cout<<" ‘ " <<str << " ‘ is a Palindrome" <<endl;
}
else
{
return false;
cout << " ‘ " << str << " ‘ is not a palindrome" <<endl;
}
return 0;
}
[i][b]this is my stach.h code[/b][/i]
#include "singlist.h"
#ifndef STACK_H
# define STACK_H
template <class dataType>
class stack : public singlist <dataType>
{
public:
void Push(dataType item);
dataType Pop();
bool Empty();
void clear();
dataType Top();
};
template <class dataType>
void stack<dataType>::Push(dataType item)
{
Add1(item);
}
template <class dataType>
bool stack<dataType>::Empty()
{
return Head= = NULL;
}
template <class dataType>
dataType stack<dataType>::Top()
{
try
{ if (Head !=NULL)
return Head->data;
else
throw "****Empty Stack****";
}
catch (char *str)
{
cout<<"caught Stack exception:" <<str;
}
}
template <class dataType>
dataType stack<dataType>::Pop()
{
dataType temp;
try
{ if (!Empty() )
{temp = Top();
Remove (temp);
return temp;
}
else
throw "****Error Empty Stack****";
}//end of try
catch (char *str)
{
cout<<"caught Stack exception:" <<str;
}// end of catch function
}// end of function
template <class dataType>
void stack<dataType>::clear ()
{
dataType trash;
if (!Empty())
while(Head=!NULL)
trash = Pop();
else
cout <<"***Cant Clear Empty Stack***" <<endl;
}
#endif
my queue code
#include "stack.h"
#ifndef QUEUE_H
#define QUEUE_H
template <class dataType>
class queue: public stack<dataType>
{
public:
void EnQueue(dataType item);
dataType DeQueue();
dataType Front();
};
template <class dataType>
void queue<dataType>::EnQueue(dataType item)
{
Add2(item);
}
template <class dataType>
dataType queue<dataType>::DeQueue()
{
try
{ if (Head !=NULL)
return Pop();
else
throw "****Empty Queue****";
}
catch (char *str)
{
cout<<"caught queue exception:" <<str;
}
}
template <class dataType>
dataType queue<dataType>::Front()
{
try
{ if (Head !=NULL)
return Top();
else
throw "****Empty Queue****";
}
catch (char *str)
{
cout<<"caught queue exception:" <<str;
}
}
#endif