/* stack2.c */ /* use of linear list for stack */ #include #include struct stack { int d; struct stack *next; }; void push(int x, struct stack **s) { struct stack *new_s; new_s = (struct stack*)malloc(sizeof(struct stack)); new_s->next = *s; new_s->d = x; *s = new_s; } void pop(int *xp, struct stack **s) { struct stack *next_s; *xp = (*s)->d; next_s = (*s)->next; free(*s); *s = next_s; } int main() { struct stack *sp; int x,y; sp = NULL; push(1,&sp); printf("%d %d %ld\n",x,y,(long int)sp); push(2,&sp); printf("%d %d %ld\n",x,y,(long int)sp); pop(&x,&sp); printf("%d %d %ld\n",x,y,(long int)sp); pop(&y,&sp); printf("%d %d %ld\n",x,y,(long int)sp); return(0); }