// // stack_using_linked_list.c // // // Created by Bibhas Ghoshal on 18/04/23. // #include struct lifo { int value; struct lifo *next; }; typedef struct lifo stack; void create (stack **top) { *top = NULL; /* top points to NULL, indicating empty stack */ } void push (stack **top, int element) { stack *new; new = (stack *) malloc(sizeof(stack)); if (new == NULL) { printf ("\n Stack is full \n"); exit(-1); } new->value = element; new->next = *top; *top = new; } int pop (stack **top) { int t; stack *p; if (*top == NULL) { printf ("\n Stack is empty\n"); exit(-1); } else { t = (*top)->value; p = *top; *top = (*top)->next; free (p); return t; } } int isempty (stack *top) { if (top == NULL) return (1); else return (0); } int main() { stack *A, *B; create(&A); create(&B); push(&A,10); push(&A,20); push(&A,30); push(&B,100); push(&B,5); printf ("\n %d %d \n", pop(&A),pop(&B)); printf ("\n %d %d \n", pop(&A),pop(&B)); push (&A, pop(&B)); // if (isempty(B)) // printf ("\n B is empty"); }