(In Java) 22.11 (Palindrome Tester) Write a program that uses astack to determine whether a string is a palindrome (i.e., thestring is spelled identically backward and forward). The programshould ignore spaces and punctuation.
Answer
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
int top = -1, front = 0;
int stack[50];
void push(char a)
{
top++;
stack[top] = a;
}
void pop()
{
top–;
}
void main()
{
int i;
char s[50], b;
clrscr();
printf(“nEnter Stringn”);
gets(s);
for(i = 0;s[i] != ”;i++)
{
if(s[i]==’ ‘)
continue;
b = s[i];
push(b);
}
for (i = 0;i<(strlen(s)/2);i++)
{
if(stack[top] == stack[front])
{
pop();
front++;
}
else if(stack[top]==’ ‘ || stack[top]==’,’ || stack[top]==’.’ ||stack[top]==’?’ || stack[top]==’!’ || stack[top]==’-‘ )
continue;
else
{
printf(“%s is not a palindromen”, s);
break;
}
}
if ((strlen(s) / 2) == front)
printf(“%s is palindromen”, s);
getch();
}
Enter