-
Notifications
You must be signed in to change notification settings - Fork 1
/
Stack_linkedlist.c
68 lines (68 loc) · 1.05 KB
/
Stack_linkedlist.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
#include<stdio.h>
#include<stdlib.h>
typedef struct node1
{
int data;
struct node1 *link;
}node;
node *top;
void push()
{
int num;
node *new;
printf("Enter data");
scanf("%d",&num);
new=(node*)malloc(sizeof(node));
new->data=num;
new->link=top;
top=new;
}
void pop()
{
if(top==NULL)
{
printf("Stack empty");
return;
}
node *ptr=top;
top=top->link;
free(ptr);
}
void display()
{
if(top==NULL)
{
printf("Stack empty");
return;
}
node *ptr=top;
while(ptr!=NULL)
{
printf("%d\n",ptr->data);
ptr=ptr->link;
}
}
int main()
{
int choice;
while(1)
{
printf("1-push\n");
printf("2-pop\n");
printf("3-Display\n");
while(1)
{
printf("Enter your choice\n");
scanf("%d",&choice);
switch(choice)
{
case 1:push();
break;
case 2:pop();
break;
case 3:display();
break;
}
}
}
}