0% found this document useful (0 votes)
12 views

Stack Using Linked List

Sstcka using linked list

Uploaded by

jeelearning2405
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

Stack Using Linked List

Sstcka using linked list

Uploaded by

jeelearning2405
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Program:-

#include<stdio.h>

#include<stdlib.h>

Typedef struct node

Int data;

Struct node *next;

}node;

Typedef struct LL

Node *start;

}LL;

Void display(LL *l)

Node *p;

If(l->start==NULL)

Printf(“\nList is empty…”);

Else

P=l->start;

While(p!=NULL)

Printf(“\n%d”,p->data);

P=p->next;

}
Void push(LL *l,int x)

Node *newrec;

Newrec=(node *)malloc(sizeof(node));

Newrec->data=x;

Newrec->next=NULL;

If(l->start==NULL)

l->start=newrec;

Else

Newrec->next=l->start;

l->start=newrec;

Void pop(LL *l)

Node *p;

If(l->start==NULL)

Printf(“\nDeletion not possible…”);

Else

P=l->start;

l->start=l->start->next;

free(p);

}
}

Int main()

Int ch,x;

LL l;

l.start=NULL;

while(1)

Printf(“\nMenu:\n1-PUSH\n2-POP\n3-DISPLAY\n4-EXIT\nEnter Choice=”);

Scanf(“%d”,&ch);

If(ch==4)

Break;

Switch(ch)

Case 1:

Printf(“\nEnter element to be inserted=”);

Scanf(“%d”,&x);

Push(&l,x);

Display(&l);

Break;

Case 2:

Pop(&l);

Display(&l);

Break;

Case 3:

{
Display(&l);

Break;

Default:

Printf(“\nInvalid Choice…”);

Return 0;

Output:-
Menu:

1-PUSH

2-POP

3-DISPLAY

4-EXIT

Enter Choice=1

Enter element to be inserted=30

30

Menu:

1-PUSH

2-POP

3-DIsPLAY

4-EXIT

Enter Choice=3

30

Menu:

1-PUSH

2-POP

3-DISPLAY
4-EXIT

Enter Choice=2

Deleted element=30

Menu:

1-PUSH

2-POP

3-DISPLAY

4-EXIT

Enter Choice=4

You might also like