-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStack Using Array.c
64 lines (64 loc) · 1.25 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
#include<stdio.h>
#include<stlib.h>
void push()
void pop()
void display()
int n,a[20],top=-1;
void main()
{
int c;
printf("Enter the size of the stack:");
scanf("%d",&n);
printf("Enter the elements:")
for(i=0;i<top;i++){
scanf("%d",&a[i]);
}
while(1)(
printf("Enter your choice 1.push 2.pop 3.display 4.exit");
scanf("%d",&c);
switch(c){
case 1: push();
break;
case 2: pop();
break;
case 3: display();
break;
case 4 : Exit(0);
break;
default : printf("Invalid Choice");
}
)
}
void push(){
int e;
if(top==n-1){
printf("Stack is full");
}
else{
printf("Enter element to be pushed");
scanf("%d",&e);
top++;
a[top]=e;
}
}
void pop(){
if(top==-1){
printf("Stack is Empty");
}
else{
printf("%d is the popped element",a[top]);
top--;
}
void display(){
if(top==-1){
printf("Stack is Empty");
}
else{
printf("The elements of the stack are:");
for(i=0;i<top;i++)
{
scanf("%d",a[i]);
}
}
}
}