-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstack.c
More file actions
68 lines (67 loc) · 1.27 KB
/
Copy pathstack.c
File metadata and controls
68 lines (67 loc) · 1.27 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
#include <stdio.h>
#include <stdlib.h>
int arr[100],top=-1,count;
void push(int element){
count++;
if(count>100){
printf("Stack Overflow:\n");
exit(0);
}
arr[++top]=element;
printf("Inserted element is:%d\n",element);
}
int pop(){
if(top==-1){
printf("List is empty!!!\n");
exit(0);
}
count --;
return arr[top--];
}
void display(){
if(top==-1){
printf("List is empty!!!\n");
return;
}
int max=top;
printf("Elements in the stack are:\n");
while(max!=-1){
printf("%d\t",arr[max]);
max--;
}
printf("\n");
}
void main(){
int num,x,del;
while(1){
int ch;
printf("Enter your choice:\n");
printf("1.Push\n2.Pop\n3.Display\n4.Exit\n\n");
scanf("%d",&ch);
switch(ch){
case 1:
printf("Enter the number of elements to be inserted in the stack\n");
scanf("%d",&num);
while(num){
printf("Enter the element to be inserted:\n");
scanf("%d",&x);
push(x);
num--;
}
break;
case 2:
del=pop();
printf("Deleted element is:%d\n",del);
break;
case 3:
display();
break;
case 4:
printf("!!!!!!!!!!!!!!!!!You have choosed to exit!!!!\n");
exit(0);
default:
printf("Exiting...\n");
return;
}
}
}