-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSTa and QUe..c
71 lines (69 loc) · 1.39 KB
/
STa and QUe..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
#include<stdio.h>
int Push(int m,int ls[m],int *top)
{
int a;
if(*top>m-1)
{
printf("\nOVERFLOW!!!");
printf("\nPop the element");
}
else
printf("\nEnter the element you want to push ");
scanf("%d",&a);
ls[*top]=a;
*top+=1;
}
void Peek(int m,int ls[m],int *top)
{
int a,len;
printf("top is %d",*top-1);
printf("\nThe *topmost element of the stack is %d ",ls[*top-1]);
}
void Pop(int m,int ls[m],int *top)
{
int a,len;
printf("\n top currently is %d",*top);
printf("\n The element currently sitting at the top(to be popped) is %d",ls[*top-1]);
*top-=1;
}
void Display(int m,int ls[m],int *top)
{
printf("\nThe Stack looks this way ");
for(int i=*top-1;i>=0;i--)
{
printf("\n%d",ls[i]);
}
}
int main()
{
int n,ch=1,c=0;
printf("Enter the number of elements in the array ");
scanf("%d",&n);
int arr[n];
printf("\n***Stack OPS***");
printf("\n 1.Push \n 2.Peek \n 3.Pop \n 4.Display \n 5. End");
while(ch>0)
{
printf("\nEnter your choice ");
scanf("%d",&ch);
switch(ch)
{
case 1:
Push(n,arr,&c);
break;
case 2:
Peek(n,arr,&c);
break;
case 3:
Pop(n,arr,&c);
break;
case 4:
Display(n,arr,&c);
break;
}
if(ch==5)
{
break;
}
}
}