-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstack_implement.c
More file actions
63 lines (58 loc) · 1.33 KB
/
Copy pathstack_implement.c
File metadata and controls
63 lines (58 loc) · 1.33 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
#include<stdio.h>
#include<stdlib.h>
#define SIZE 10
int *arr=NULL;
int top=-1;
int main()
{
arr=(int *)malloc(sizeof(int)*SIZE);
while(1)
{
//infinite loop to perform operation
printf("Press 1 to push.\nPress 2 to pop.\nPress 3 to view top.\nPress 4 to show all elements of stack.\nPress any other key to exit.\n");
int choice;
scanf("%d",&choice);
if(choice==1)
{
system("clear");
int data;
printf("ENTER DATA : ");
scanf("%d",&data);
if(top+1<SIZE)
{
arr[++top]=data;
}
else
printf("STACK FULL.\n");
}
else if(choice==2)
{
system("clear");
if(top>=0)
{
top--;
}
else
printf("STACK ALREADY EMPTY.\n");
}
else if(choice==3)
{
system("clear");
if(top!=-1)
printf("TOP ELEMENT : %d\n",arr[top]);
else
printf("STACK IS EMPTY.\n");
}
else if(choice==4)
{
system("clear");
while(top>=0)
{
printf("%d , ",arr[top--]);
}
printf("\n");
}
else
break;
}
}