Please spot the errors and right the correct code back .
Thanks in advance
amit kumar
#include<stdio.h>
#define max 10
typedef struct
{
char entry[max];
int top;
}stack;
int stackfull(stack *s)
{
if(s->top==max)
return 0;
else
return 1;
}
int stackempty(stack *s)
{
if(!(s->top=-1))
return 0;
else
return 1;
}
void push(stack *stk,char data)
{
if(!(stackfull(stk)))
stk->entry[stk->top++]=data;/*try ++top */
}
char pop(stack *stk)
{ if(!(stackempty(stk)))
return(stk->entry[stk->top--]);
else
return NULL;
}
void show(stack *stk)
{
int temp=stk->top;
while(!(temp<0))
printf(" %c \n ",stk->entry[temp--]);
}
void createstack(stack *s)
{
s->top=-1;
}
char stacktop(stack *stk)
{
return (stk->entry[stk->top]);
}
void clearstack(stack *stk)
{
stk->top=-1;
}
int stacksize(stack *stk)
{
return ((stk->top)+1);
}
int main()
{
stack stk;
createstack(&stk);
int n,k;
char data;
for(k=0;k<4;++k) /* test */
{
printf("\n enter push or pop or show ,1,2,3");
scanf(" %d ",&n);
switch(n)
{
case 1:
printf("\n enter data ");
scanf(" %c ",&data);
push(&stk,data);
break;
case 2:
printf(" the data removed is %c",pop(&stk));
break;
case 3:
show(&stk);
printf(" the stack top is %c ",stacktop(&stk));
printf(" the stack size is %d ",stacksize(&stk));
clearstack(&stk);
show(&stk);
break;
default: printf("\n wrong case entered ");
}
}
return 0;
}