forked from nayyyhaa/C-codes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.c
More file actions
109 lines (102 loc) · 1.74 KB
/
stack.c
File metadata and controls
109 lines (102 loc) · 1.74 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include <stdio.h>
#include <stdlib.h>
#define MAX 3
int top=0;
int arr[MAX];
void display()
{
int i;
if(top==0)
{
printf("Stack is empty");
}
else
{
printf("Elements in stack are : ");
for(i=0;i<top;i++)
{
printf("%d ",arr[i]);
}
}
}
void push(int num)
{
if(top==MAX)
{
printf("Stack Overflow");
}
else
{
arr[top]=num;
top++;
printf("Elemet pushed.\n");
display();
}
}
void pop()
{
if(top==0)
{
printf("Stack Underflow");
}
else
{
top--;
printf("Deleted element is %d\n",arr[top]);
display();
}
}
void wait()
{
printf("\n\n");
printf("Press ENTER to continue...");
getchar();
getchar();
}
int main()
{
int choice;
int element;
while(1)
{
system("clear");
printf(" STACK DATA STRUCTURE");
printf("\n");
printf("--------------------------------------------------------------------------------");
printf("\n\n");
printf("List of Operations : 1. Push\n");
printf(" 2. Pop\n");
printf(" 3. Display\n");
printf(" 0. Exit\n");
printf("\n\n\n");
printf("Enter the Number of Operation you want to perform : ");
scanf("%d",&choice);
printf("\n\n");
switch(choice)
{
case 1:
printf("Enter the number you want to push : ");
scanf("%d",&element);
push(element);
wait();
break;
case 2:
pop();
wait();
break;
case 3:
display();
wait();
break;
case 0:
wait();
exit(0);
break;
default:
printf("Wrong input....");
printf("\n");
wait();
}
}
return 0;
}