#include #include #include struct Node { int data; struct Node *ptr; }; struct Node *top = NULL; void push(int v) { struct Node *new = (struct Node *)malloc(sizeof(struct Node)); new->data = v; new->ptr = top; top = new; } int pop() { struct Node *temp = top; int v = temp->data; top = temp->ptr; free(temp); return v; } int peek() { if (top == NULL) { printf("Stack empty\n"); return -1; } return top->data; } void display() { struct Node *temp = top; printf("Stack: "); while (temp != NULL) { printf("%d ", temp->data); temp = temp->ptr; } printf("\n"); } int main() { push(10); push(20); push(30); display(); printf("Popped: %d\n", pop()); display(); printf("Top: %d\n", peek()); }