-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstackUsingArray.c
More file actions
73 lines (73 loc) · 1.59 KB
/
stackUsingArray.c
File metadata and controls
73 lines (73 loc) · 1.59 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
#include <stdio.h>
#define N 5
int top=-1;
int arr[N];
void push(){
int data;
printf("Enter the data:\n");
scanf("%d",&data);
if(top==N-1){
printf("Overflow condition Occur.No more element is inserted\n");
return;
}
else{
top++;
arr[top]=data;
}
}
void pop(){
if(top==-1){
printf("Underflow condition occur.\n");
}
else{
printf("The data that ia pop is:%d\n",arr[top]);
top--;
}
}
void peek(){
if(top==-1){
printf("The stack is empty no element is present.\n");
return;
}
else{
printf("The topmost element of stack is:%d\n",arr[top]);
}
}
void display(){
if(top==-1){
printf("The stack is empty no element is present.\n");
return;
}
else{
for(int i=0;i<=top;i++){
printf("%d ",arr[i]);
}
printf("\n");
}
}
int main(){
int choice,choice1=1;
while(choice1==1){
printf("Enter Choice:\n1.Enter 1 to insert an element in stack\n2.Enter 2 delete an element from Stack\n3.Enter 3 to print the topmost element of stack\n4 Enter 4 to display the element of Stack.\n");
scanf("%d",&choice);
switch(choice){
case 1:
push();
break;
case 2:
pop();
break;
case 3:
peek();
break;
case 4:
display();
break;
default:
printf("Wrong choice enter.\n");
}
printf("1.Enter 1 to Continue.\n2.Enter any number to discontinue.\n");
scanf("%d",&choice1);
}
return 0;
}