/* Program for palindrome using a dynamic stack */
#include<stdio.h>
#include<stdlib.h>
#include "stack2.h" //implementation of dynamic stack
int main()
{
stack *TOP;
char x[30];
int i;
init(&TOP);
printf("\nEnter a string : ");
for(i=0;(x[i]=getchar())!='\n';i++)
push(&TOP,x[i]);
x[i]='\0';
i=0;
while(!empty(TOP))
{
if(x[i]!=pop(&TOP))
break;
else
i++;
}
if(empty(TOP))
printf("\nA palindrome ");
else
printf("\nNot a palindrome");
}
No comments:
Post a Comment