-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathStack_Using_Arrays.c
More file actions
57 lines (56 loc) · 956 Bytes
/
Copy pathStack_Using_Arrays.c
File metadata and controls
57 lines (56 loc) · 956 Bytes
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
#include<stdio.h>
#define SIZE 50
int top = -1,stack[SIZE],item;
//push
void push()
{
//overflow check
if(top == SIZE-1)
printf("OVERFLOW!!!");
else
{
printf("Enter data \t:");
scanf("%d",&item);
stack[++top] = item;
}
}
//pop
void pop()
{
//if Underflow
if(top == -1)
printf("UNDERFLOW");
else
{
printf("Deleted element is : %d",stack[top--]);
}
}
//display
void display()
{
int i;
printf("\n");
for(i = top; i>-1; i--)
{
printf("%d\n",stack[i]);
}
}
void main()
{
int ch;
while(1)
{
printf("\t\t\tStack\n1.Push\n2.Pop\n3.Display\n");
scanf("%d",&ch);
switch(ch)
{
case 1: push();
break;
case 2: pop();
break;
case 3: display();
break;
default: printf("invalid input try again");
}
}
}