-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathStack-LL.c
More file actions
90 lines (86 loc) · 1.52 KB
/
Copy pathStack-LL.c
File metadata and controls
90 lines (86 loc) · 1.52 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
#include<stdio.h>
#include<stdlib.h>
struct newnode
{
int data;
struct newnode *link;
} *top=NULL;
typedef struct newnode newnode;
void Push(int x)
{
newnode *temp;
temp=(newnode*)malloc(sizeof(newnode));
temp->data=x;
temp->link=top;
top=temp;
}
void Pop()
{
newnode *q;
if ((top==NULL))
{
printf("Stack Underflow\n");
}
else
{
printf("the element %d has been popped out of the stack\n",top->data);
q=top;
top=top->link;
free(q);
}
}
void Peek()
{
if ((top==NULL))
{
printf("Stack Underflow\n");
}
else{
printf("the element %d is at the top of the stack\n",top->data);
}
}
void Display()
{
newnode *q;
q=top;
while(q!=NULL)
{
printf("%d\t",q->data);
q=q->link;
}
printf("\n");
}
int main()
{
int ch;
int n;
do
{
printf("Press 1 for push\n");
printf("Press 2 for pop\n");
printf("press 3 for peek\n");
printf("press 4 for display\n");
printf("press 0 for exit\n");
scanf("%d",&ch);
switch (ch)
{
case 1:
printf("Enter the item you want to push in the stack\n");
scanf("%d",&n);
Push(n);
break;
case 2:
Pop();
break;
case 3:
Peek();
break;
case 4:
Display();
break;
default:
printf("Invalid choice\n");
break;
}
} while (ch !=0);
}