-
Notifications
You must be signed in to change notification settings - Fork 1
/
STACK_Operations_lab3.c
72 lines (71 loc) · 1.71 KB
/
STACK_Operations_lab3.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
65
66
67
68
69
70
71
72
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,ch;
printf("IMPLEMENTATION OF STACK OPERATIONS\n");
printf("Enter the number of elements in the stack: ");
scanf("%d", &n);
int *stk=(int*)malloc(sizeof(int)*n);
int top=-1;
do
{
printf("1.\tPUSH\n2.\tPOP\n3.\tDISPLAY\n4.\tEXIT");
printf("\nChoice: ");
scanf("%d",&ch);
switch(ch)
{
case 1:
{
if(top==n-1)
{
printf("Stack is full!Overflow!\n");
getch();
break;
}
else
{
printf("Enter the element: ");
top++;
scanf("%d",&stk[top]);
}
break;
}
case 2:
{
if(top==-1)
{
printf("Stack is empty!Underflow!\n");
getch();
break;
}
else
{
printf("Element Popped: %d",stk[top]);
top--;
}
break;
}
case 3:
{
if(top==-1)
{
printf("Empty Stack!\n");
getch();
break;
}
else
{
for(i=0;i<=top;i++)
{
printf("%d\t",stk[i]);
}
getch();
}
break;
}
case 4: exit(1);
default: printf("Invalid Choice\n");
}
}while(ch!=4);
}