-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStack Implementations.c
More file actions
82 lines (80 loc) · 1.74 KB
/
Stack Implementations.c
File metadata and controls
82 lines (80 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
#include<stdio.h>
int size=5;
struct stack{
int a[5];
int top;
};
void push(struct stack *ptr)
{ int info;
printf("ENTER THE VALUE TO PUSH INTO STACK: \n");
scanf("%d",&info);
if(ptr->top==size-1)
{printf("STACK OVERFLOW!!");
return;
}
ptr->top=ptr->top+1;
ptr->a[ptr->top]=info;
printf("%d is INSERTED INTO STACK\n",info);
}
int pop(struct stack *ptr)
{
if(ptr->top==-1)
{
printf("STACK IS EMPTY!\n");
return;
}
int item=ptr->a[ptr->top];
ptr->top=ptr->top-1;
return item;
}
void display(struct stack *ptr)
{ int i;
if(ptr->top==-1)
{
printf("STACK IS EMPTY!\n");
return;
}
for(i=ptr->top;i>0;i--)
printf(" %d \n",ptr->a[i]);
}
void main()
{
struct stack *ptr;int choice;
ptr=(struct stack*)malloc(sizeof(struct stack));
int i,ar[size];
ptr->top=-1;
do
{ printf("STACK OPERATIONS USING ARRAY::");
printf("\n\t 1.PUSH\n\t 2.POP\n\t 3.DISPLAY\n\t 4.EXIT");
printf("\n Enter the Choice:");
scanf("%d",&choice);
switch(choice)
{
case 1:
{
push(ptr);
break;
}
case 2:
{
pop(ptr);
break;
}
case 3:
{
display(ptr);
break;
}
case 4:
{
printf("\n\t EXIT POINT ");
break;
}
default:
{
printf ("\n\t Please Enter a Valid Choice(1/2/3/4)\n");
}
}
}
while(choice!=4);
}