-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path19_stackll.c
67 lines (60 loc) · 1.35 KB
/
19_stackll.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//Govind J Nair
//S3-D
//23
#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node *link;
};
void main()
{
int cho;
struct node *temp,*top,*head;
temp=(struct node*)malloc(sizeof(struct node));
temp->data=0;
temp->link=NULL;
head=temp;
top=head->link;
do
{
printf("\nMENU\n1.PUSH\n2.POP\n3.DISPLAY\n4.EXIT\nEnter Choice: ");
scanf("%d",&cho);
if(cho==1)
{
temp=(struct node*)malloc(sizeof(struct node));
printf("enter the element: ");
scanf("%d",&temp->data);
temp->link=head->link;
head->link=temp;
top=head->link;
}
else if(cho==2)
{
if(top==NULL)
{
printf("stack is empty!!!");
}
else
{
printf("popped out: %d",top->data);
temp=top;
top=top->link;
head->link=top;
free(temp);
}
}
else if(cho==3)
{
printf("elements: ");
temp=top;
while(temp!=NULL)
{
printf("%d ->",temp->data);
temp=temp->link;
}
printf("NULL");
}
}while(cho==1 || cho==2 || cho==3);
}