- Note that we have to use the second design. Modify the pop
operation to: erase(), cursor--;
- make cursor protected member instead of private
- protected members are accessible in the derived classes
- in the driver program, declare a variable of the type stack
of let us say characters;
stack<char,77> s;
char ch[80];
for (int j =0; ch[j]; j++)
{
cin >> ch[j];
if(ch[j] != '\n')
s.push(ch[j]);
else
ch[j] = 0;
}
- string such as madam will be stored in the ch as:
- and on the stack as:
- write another loop that pops out the items from the stack
using a combination of top() and pop()
- store the popped characters in another array called say reversed
if(strcmp(ch,reversed)) cout << "Not pallindrome\n";
else cout << "Pallindrome\n";