-
Notifications
You must be signed in to change notification settings - Fork 242
/
Copy pathstackll.c
77 lines (68 loc) · 1.1 KB
/
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
68
69
70
71
72
73
74
75
76
77
#include<stdio.h>
#include<malloc.h>
struct NODE {
int info;
struct NODE *link;
} ;
typedef struct NODE node;
node *top=NULL;
node *newnode(int val) {
node *p;
p=(node *)malloc(sizeof(node));
p->info=val;
p->link=NULL;
return p;
}
void Display() {
node *curr;
curr=top;
while(curr!=NULL) {
printf("%d", curr->info);
curr=curr->link;
if(curr !=NULL)
printf(" --> ");
}
}
void push(int item) {
node *p;
p=newnode(item);
if(p==NULL)
printf("overflow");
else
p->info = item;
p->link = top;
top = p;
}
void pop() {
node *ptr;
ptr = top;
if(ptr == NULL)
printf("Underflow");
else
ptr = top;
top = top->link;
free(ptr);
}
void main() {
int ch,item;
do {
printf("\n1. Insert \n2. Delete\n3. Display\n4. Quit\nEnter your Choice : ");
scanf("%d",&ch);
switch(ch) {
case 1:
printf("\nvalue to be inserted:");
scanf("%d",&item);
push(item);
break;
case 2:
pop();
break;
case 3:
Display();
break;
case 4:
break;
default:printf("Invalid choice");
}
}while(ch!=4);
}