Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ********************************
- ********************************
- ****STACK USING LINKED LIST ****
- ********************************
- ********************************
- */
- #include<stdio.h>
- #include<conio.h>
- #include<malloc.h>
- typedef struct node {
- int data;
- struct node *next;
- }node;
- node *top;
- void push() {
- node *p;
- int x;
- p=(node *)malloc(sizeof(node));
- printf("enter the data \t\n");
- scanf("%d",&x);
- p->data=x;
- p->next=top;
- top=p;
- }
- void pop() {
- int x;
- node *p;
- p=top;
- top=p->next;
- x=p->data;
- printf("THE POPPED ELEMENT IS %d ", x);
- free(p);
- }
- void display() {
- node *p;
- p=top;
- while(p!=NULL) {
- printf("\t%d",p->data);
- p=p->next;
- }
- }
- main() {
- int i;
- do{
- printf("\n1.PUSH\n2.POP\n3.DISPLAY\n4.EXIT");
- scanf("%d",&i);
- switch(i) {
- case 1:
- push(); break;
- case 2:
- pop(); break;
- case 3:
- display(); break;
- }
- }while(i!=4);
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment