-
Notifications
You must be signed in to change notification settings - Fork 0
/
stack.c
83 lines (79 loc) · 1.38 KB
/
stack.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
78
79
80
81
82
83
#include<stdio.h>
#include<stdlib.h>
int stack[100],size=3,top=0;
void push(int element)
{
if(top==size)
{
printf("stack full");
}
else
{
stack[top]=element;
top=top+1;
}
}
int pop()
{
int element;
if(top==0)
{
printf("stack is empty");
}
else
{
top=top-1;
element=stack[top];
return element;
}
}
int peak()
{
if(top==0)
printf("stack is empty");
else
{
printf("\n%d\n",stack[top-1]);
}
}
void display()
{
int i;
if(top==0)
printf("stack is empty");
else
{
for(i=top-1;i>=0;i--)
{
printf("\n%d\n",stack[i]);
}
}
}
void main()
{
int choice,element;
do
{
printf("\n1.PUSH\n2.POP\n3.PEAK\n");
printf("enter the choice");
scanf("%d",&choice);
switch(choice)
{
case 1:printf("enter element to be pushed");
scanf("%d",&element);
push(element);
display();
break;
case 2:pop();
display();
break;
case 3:peak();
break;
default:exit(0);
break;
}
}while(choice<5);
{
printf("invalid");
}
}