-
Notifications
You must be signed in to change notification settings - Fork 0
/
DynamicStack.c
69 lines (64 loc) · 1.2 KB
/
DynamicStack.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
#include<stdio.h>
#include<malloc.h>
struct list
{
int data;
struct list *link;
}*top=NULL;
void push()
{
int n;
printf("Enter number: ");
scanf("%d",&n);
struct list *temp;
temp=(struct list*)malloc(sizeof(struct list));
temp->data=n;
temp->link=top;
top=temp;
}
void pop()
{
struct list *temp;
if(top==NULL)
printf("Stack is empty");
else
{
temp=top;
printf("Deleted element is %d",temp->data);
top=top->link;
free(temp);
}
}
void display()
{
struct list *q;
if(top==NULL)
printf("Stack is empty");
else
{
q=top;
while (q!=NULL)
{
printf("%d->",q->data);
q=q->link;
}
}
}
void main()
{
int i,c;
printf("------MENU------\n1. Push\n2. Pop\n3. Display\n4. Exit");
while (c)
{
printf("\n\nEnter your choice: ");
scanf("%d",&c);
switch (c)
{
case 1: push(); break;
case 2: pop(); break;
case 3: display(); break;
case 4: exit(0); break;
default: printf("Invalid input"); break;
}
}
}