forked from RAJAT1402/HACTOBERFEST2020
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSTACK.CPP
79 lines (72 loc) · 1.57 KB
/
STACK.CPP
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
#include<stdio.h>
#include<conio.h>
void push();
void pop();
void display();
void peek();
void isempty();
void isfull();
void main()
{ clrscr();
int element,a,stack[5],size=5,top=-1;
do{ printf("\n--------MENU--------\n");
printf("1.PUSH ELEMENT IN STACK\n");
printf("2.POP ELEMENT FROM STACK\n");
printf("3.DISPLAY ELEMENTS IN STACK\n");
printf("4.PEEK ELEMENT\n");
printf("5.ISEMPTY\n");
printf("6.ISFULL\n");
printf("7.QUIT\n");
printf("enter your choice = ");
scanf("%d",&a);
switch(a)
{ case 1:push(stack,size,top);break;
case 2:pop(stack,top);break;
case 3:display(stack,top);break;
case 4:peek(stack,top);break;
case 5:isempty(top);break;
case 6:isfull(top);break;
case 7:break;
default :printf("wrong choice enter again\n");
}
}while(a!=7);
getch();
}
void peek(int stack[],int &top)
{
printf("PEEK ELEMENT = %d",stack[top]);
}
void push(int stack[],int size,int &top)
{ int element;
printf("element to be pushed =");
scanf("%d",&element);
if(top==size-1)
printf("stack overflow\n");
else
stack[++top]=element;
}
void pop(int stack[],int &top)
{ if(top==-1)
printf("stack underflow\n");
else
printf("poped element =%d",stack[top--]);
}
void display(int stack[],int &top)
{
for(int i=top;i>=0;i--)
printf(" %d",stack[i]);
}
void isempty(int &top)
{
if(top==-1)
printf("Stack is empty");
else
printf("Stack is not empty");
}
void isfull(int &top)
{
if(top==4)
printf("Stack is Full");
else
printf("Stack is not full");
}