-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSTACKARR.c
More file actions
83 lines (82 loc) · 1.36 KB
/
STACKARR.c
File metadata and controls
83 lines (82 loc) · 1.36 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
#include<stdio.h>
#include<stdlib.h>//used for exit() function
#define MAX 15
int a[MAX],top;//Global Variable
void push(int x)
{
if(top==MAX-1)
{
printf("Stack is Full. Can't Push\n");
}
else
{
top++;
a[top]=x;
}
}
void pop()
{
if(top==-1)
{
printf("The Stack is Empty. Can't pop\n");
}
else
{
printf("The popped element is %d",a[top]);
top--;
}
}
void display()
{
int i;
if(top==-1)
{
printf("Empty Stack. Nothing to display");
}
else
{
printf("The elements of the Stack are ");
for(i=0;i<=top;i++)
printf("%d ",a[i]);
}
}
void menu()
{
printf("\n");
printf("\t\t\t PROGRAM ON Stack\n");
printf("\t\t\t 1. PUSH\n");
printf("\t\t\t 2. POP\n");
printf("\t\t\t 3. DISPLAY\n");
printf("\t\t\t 4. EXIT\n");
printf("Enter your choice ");
}
int main()
{
int ch,m;
top=-1;
while(875)//Infinite Loop. Another technique: while(Any NON ZERO VALUE)
{
menu();
scanf("%d",&ch);//Accept choice
switch(ch)
{
case 1:
printf("\nEnter the number to push ");
scanf("%d",&m);//"m" will be pushed
push(m);
break;
case 2:
pop();
break;
case 3:
display();
break;
case 4:
exit(0);//Exit from the program
default:
printf("\nInvalid choice \n");
break;
}//End of switch
}//End of while loop
return 0;
}