-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathStack_DataStructure.c
More file actions
71 lines (70 loc) · 1 KB
/
Copy pathStack_DataStructure.c
File metadata and controls
71 lines (70 loc) · 1 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
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int stk[100];
int index=0;
int n=5;
void push(int k)
{
if(index<n)
{
stk[index]=k;
index++;
}
else
{
printf("Stack is FULL!!\n");
}
}
void pop()
{
if(index!=0)
{
printf("Element popped out is:%d\n",stk[index-1]);
index--;
}
else
{
printf("Stack is EMPTY!!\n");
}
}
void print()
{
if(index==0)
{
printf("Stack is EMPTY!!\n");
}
else
{
int i=0;
printf("The elements in STACK are:\n");
while(i<index)
{
printf("%d\n",stk[i]);
i++;
}
}
}
int main()
{
int a,k;
while(1)
{
printf("Select your option:\n");
printf("1.Push\n2.Pop\n3.Print\n4.Exit\n");
scanf("%d",&a);
switch(a)
{
case 1: printf("Enter the element to be pushed into the stack:");
scanf("%d",&k);
push(k);
break;
case 2: pop();
break;
case 3: print();
break;
case 4: exit(0);
}
}
getch();
}