-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStackArray.c
More file actions
96 lines (95 loc) · 2.41 KB
/
Copy pathStackArray.c
File metadata and controls
96 lines (95 loc) · 2.41 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
91
92
93
94
95
96
#include<stdio.h>
#define size 50
int stack[size], top=0, choice, element;
int isfull()
{
if (top==size)
return 1;
else
return 0;
}
int isempty()
{
if (top==0)
return 1;
else
return 0;
}
void push(int element)
{
if (isfull())
printf("\nStack is full, cannot push values");
else
stack[top++]=element;
}
int pop()
{
if (isempty())
return -1;
else
{
top=top-1;
return (stack[top]);
}
}
int peek()
{
if (isempty())
{
printf("\nStack is Empty, Peek Failed");
return 0;
}
else
return (stack[top-1]);
}
int displayStack()
{
int i;
for (i=top-1; i>=0; i--)
printf("\n%d",stack[i]);
}
void main()
{
int a=0,b,c,choice;
do
{
printf("\n--------Menu--------");
printf("\n1.Push\n2.Pop\n3.Peek\n4.IsFull\n5.IsEmpty\n6.Display Stack\n7.Exit");
printf("\nEnter your Choice:");
scanf("%d",&choice);
switch(choice)
{
case 1: printf("\nEnter the element to be pushed:");
scanf("%d",&element);
push(element);
break;
case 2: element=pop();
if(element==-1)
printf ("Stack is Empty, Cannot Pop Values");
else
printf("\nPopped Element is %d",x);
break;
case 3: a=peek();
if(a!=0)
printf("The Element at the top is %d",a);
break;
case 4: b=isfull();
if (b==1)
printf("\nStack is Full");
else
printf("\nStack is Not Full");
break;
case 5: c=isempty();
if (c==1)
printf("\nStack is Empty");
else
printf("\nStack is Not Empty");
break;
case 6: displayStack();
break;
case 7: break;
default: printf("\nInvalid Choice");
}
}
while (choice!=7);
}