forked from tanus786/CP-Codes-HackOctober-Fest-2023
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.c
More file actions
71 lines (57 loc) · 1.55 KB
/
stack.c
File metadata and controls
71 lines (57 loc) · 1.55 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
#include<stdio.h>
#include<stdlib.h>
#define max 15
void main()
{
int stack[max],top,ch,ele,x,ch1;
top=-1;
printf("\n 1-PUSH,2-POP,\n3-DISPLAY");
do
{
printf("\nENTER the your choice:");
scanf("%d",&ch);
switch(ch)
{
case 1:
if (top==max-1)
{
printf("insertion cannot be perferfom.");
}
else{
printf("\nenter the new element:");
scanf("%d",&ele);
top++;
stack[top]=ele;
printf("element pushed succusesfully");
}
break;
case 2:
if (top==-1)
{
printf("pop cannot be perferfom.");
}
else{
x=stack[top];
printf("%d \nis the pop:",x);
top--;
}
break;
case 3:
if (top==-1)
{
printf("stack is empyty.");
}
else{
for (int i = top; i >=0 ; i--)
{
printf("%d\t",stack[i]);
}
}
break;
default:
printf("\nenter the correct choice");
}
printf("\ndo you want to repeat? press");
scanf("%d",&ch1);
}while(ch1==1);
}