-
Notifications
You must be signed in to change notification settings - Fork 62
/
STACK IMPLEMENTATION
71 lines (61 loc) · 1.11 KB
/
STACK IMPLEMENTATION
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 a[],int top)
{ char c;
S: top++;
scanf("%d",&a[top]);
printf("Want to push more?(y/n):");fflush(stdin);
scanf("%c",&c);
if(c=='y')
goto S;
return top;
}
int pop(int a[],int top)
{
if(top == -1)
printf(" -->>Stack is Underflow <<--");
else
{
printf("Element %d popped!",a[top]);
top=top-1;
}
return top;
}
void display(int a[],int top)
{
for(int i=top;i>=0;i--)
printf("%d\n",a[i]);
}
void peek(int a[],int top)
{
printf("%d\n",a[top]);
}
#define Max 10
int main()
{
int stack[Max],top=-1,ch;
char c;
A: printf("\tMenu \n 1 Push \n 2 Pop \n 3 Display \n 4 Peek ");
printf("\nEnter your choice: ");
scanf("%d",&ch);
switch(ch)
{
case 1:
top= push(stack,top);
break;
case 2:
top=pop(stack,top);
break;
case 3:display(stack,top);
break;
case 4:peek(stack,top);
break;
default:
printf("Wrong input!");
break;
}
printf("\nMENU?(y/n): ");fflush(stdin);
scanf("%c",&c);
if(c=='y')
goto A;
return 0;
}