-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstack using array.c
73 lines (65 loc) · 1.01 KB
/
stack using array.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
66
67
68
69
70
71
72
73
#include<stdio.h>
#include<string.h>
int stack[10],top=-1,mxsize=10;
void push()
{
if(top>=mxsize-1)
{printf("Overflow\n");
return;
}
else
{
int data;
printf("Enter data to push\n");
scanf("%d",&data);
top+=1;
stack[top]=data;
printf("DONE\n");
}
}
int pop()
{
if(top<0)
{
printf("Underflow\n");
return;
}
else
{
int poped_d=stack[top];
top-=1;
printf("DONE\n");
return poped_d;
}
}
void display()
{
int i=top;
printf("\nSTACK IS");
while(i!=-1)
{
printf("%d\n",stack[i]);
i-=1;
}
printf("\n");
}
void main()
{
int ch;
char str[10];
printf("Enter ""push"" to push into the stack\n");
printf("Enter ""pop"" to pop data from the stack\n");
printf("Enter ""display"" to display the stack\n");
while(1>0)
{
scanf("%s",&str);
if(strcmp(str,"push")==0)
push();
if(strcmp(str,"pop")==0)
pop();
if(strcmp(str,"display")==0)
display();
else if(str=="exit")
return;
}
}