Check Input String in form xCy where x is string and y is Reverse of x.
#include<conio.h>
#include<string.h>
void push(int *top,char s[],char x,int max);
int pop(int *top,char s[]);
void push(int *top,char s[],char x,int max)
{
if(*top>=max-1)
{
printf("stack overflow \n");
}
else
{
*top=*top+1;
s[*top]=x;
}
}
int pop(int * top,char s[])
{
if(*top<=-1)
{
printf("stack underflow\n");
return 1;
}
else
{
int item=s[*top];
*top=*top-1;
return item;
}
}
void main()
{
int *top,max=10,i,flag,len;
char s[10],x[10],a;
*top=-1;
clrscr();
printf("enter string in format xCy:"); // x is string and y is reverse of x.
gets(x);
len=strlen(x);
for(i=0;x[i]!='C';i++)
{
push(top,s,x[i],max);
}
i++;
while(x[i]!='\0')
{
a=pop(top,s);
if(a!=x[i])
{
flag=1;
break;
}
else
{
flag=0;
}
i++;
}
if(flag==0)
{
printf("Correct");
}
else
{
printf("Not Correct");
}
getch();
}
Comments
Post a Comment