Saturday, September 3, 2011

Stack





typedef struct stack
{
char data;
struct stack *next;
} stack;
void init(stack **T)
{
*T=NULL;
}
int empty(stack *TOP)
{
if(TOP==NULL)
return(1);
return(0);
}
void push(stack **T,char x)
{
stack *P;
P=(stack *)malloc(sizeof(stack));
P->data=x;
P->next=*T;
*T=P;
}
char pop(stack **T)
{
char x;
stack * P;
P=*T;
*T=P->next;
x=P->data;
free(P);
return(x);
}
void print(stack *p)
 { printf("\n");
  while(p!=NULL)
   {printf("%c  ",p->data);
    p=p->next;
   }
}

No comments:

Post a Comment