-
Notifications
You must be signed in to change notification settings - Fork 2
/
static_stack.c
69 lines (61 loc) · 873 Bytes
/
static_stack.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
/* Static Stack*/
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define size 4
int stack[size],top=-1; /* top has the index of top element */
void push()
{
if(top!=(size-1))
{
top++;
int n;
printf("\n enter the number\n");
scanf("%d",&n);
stack[top]=n;
}
else
{
printf("\n StackOverflow\n");
}
}
void traverse()
{
int i;
if(top!=-1)
{
printf("\n elements of Stack are: \n");
for(i=top;i>=0;i--)
{
printf(" %d",stack[i]);
}
}
else
{
printf("\n Stack is empty\n");
}
}
void main()
{
int ch;
do
{
printf("\n Press 1 to push the element in Stack\n");
printf("\n Press 2 to traverse the elements of Stack\n");
printf("\n Press 3 to exit\n");
scanf("%d",&ch);
switch(ch)
{
case 1: push();
break;
case 2: traverse();
break;
case 3: exit(0);
break;
default: printf("WRONG cHOICE");
}
printf("\n Press 0 to continue\n");
scanf("%d",&ch);
}
while(ch==0);
}