-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2.stack_list.c
More file actions
135 lines (118 loc) · 1.6 KB
/
2.stack_list.c
File metadata and controls
135 lines (118 loc) · 1.6 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
//Stack implementation using Linked list
#include<stdio.h>
#include<malloc.h>
struct node
{
int data;
struct node *next;
}
*top;
void insert()
{
struct node *np;
np=(struct node *)malloc(sizeof(struct node));
printf("\n Enter the no. to be inserted : \n");
scanf("%d",&np->data);
np->next = NULL;
if(top==NULL)
top=np;
else
{
np->next = top;
top=np;
}
}
void pop()
{
struct node *np;
if(top==NULL)
printf("\n Empty stack");
else
top = top->next;
}
void display()
{
struct node *np;
np=top;
if(np==NULL)
printf("\nStack empty");
else
{
printf("\nStack contains : \n");
while(np != NULL)
{
printf("\t%d",np->data);
np=np->next;
}
printf("\n");
}
}
void main()
{
int c,n;
do
{
printf("\nEnter the choice \n1.Push\n2.Pop\n3.Display\n");
scanf("%d",&c);
switch(c)
{
case 1 : insert();
break;
case 2 : pop();
break;
case 3 : display();
break;
default : printf("\n Invalid entry\n");
}
printf("Do you want to continue/exit 1/0 ?\n");
scanf("%d",&c);
}
while(c);
}
//End of Program
/*
OUTPUT
---------------
Enter the choice
1.Push
2.Pop
3.Display
1
Enter the no. to be inserted :
65
Do you want to continue/exit 1/0 ?
1
Enter the choice
1.Push
2.Pop
3.Display
1
Enter the no. to be inserted :
98
Do you want to continue/exit 1/0 ?
1
Enter the choice
1.Push
2.Pop
3.Display
3
Stack contains :
98 65
Do you want to continue/exit 1/0 ?
1
Enter the choice
1.Push
2.Pop
3.Display
2
Do you want to continue/exit 1/0 ?
1
Enter the choice
1.Push
2.Pop
3.Display
3
Stack contains :
65
Do you want to continue/exit 1/0 ?
0 */