forked from TECHOUS/DSKaKhel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbasicPushPop.cpp
More file actions
54 lines (50 loc) · 1 KB
/
basicPushPop.cpp
File metadata and controls
54 lines (50 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
#include<stdio.h>
#include<malloc.h>
int top = 0;
int * STACK;
void push(int value)
{
STACK[top++] = value;
}
int pop()
{
top--;
return STACK[top];
}
void display()
{
for(int i = top ; i >= 0 ; i--)
{
printf("%d\n",STACK[i]);
}
}
int main()
{
int size,choice,element;
printf("Enter the size of the stack\n");
scanf("%d",&size);
STACK = (int *) malloc(size * sizeof(int));
printf("ENTER YOUR CHOICE\n1.PUSH()\n2.POP() and display the popped element\n3.display()\n");
scanf("%d",&choice);
while(choice != -1)
{
switch(choice)
{
case 1:
printf("\nENTER THE ELEMENT TO PUSH\n");
scanf("%d",&element);
push(element);
break;
case 2:
printf("\nThe popped element is : %d\n",pop());
break;
case 3:
printf("\nTHIS IS THE DISPLAY PART\n");
display();
break;
}
printf("\nENTER YOUR CHOICE\n1.PUSH()\n2.POP() and display the popped element\n3.display()\n");
scanf("%d",&choice);
}
return 0;
}