Repository navigation
Expand file tree
/
Copy pathStack(Array)
More file actions
94 lines (85 loc) · 1.67 KB
/
Copy pathStack(Array)
File metadata and controls
94 lines (85 loc) · 1.67 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
83
84
85
86
87
88
89
90
91
92
93
94
#include<stdio.h>
#include<memory.h>
#include<stdlib.h>
int SIZE = 5,top = -1, stack[SIZE];
void menu();
void push();
void pop;
void peek();
void display();
int main(){
int choice=0;
do{
system("cls");
menu();
printf("\nEnter your choice:");
scanf("%d", &choice);
switch(choice){
case 1: push();
break;
case 2: pop();
break;
case 3: peek();
break;
case 4: display();
break;
default: printf("Thank you for using thid program");
break;
}
getch();
}while(choice>0 && choice<5);
return 0;
}
void menu(){
printf("=========================================================");
printf(" Menu ");
printf("=========================================================");
printf("->Enter 1 for push operaton");
printf("->Enter 2 for pop operaton");
printf("->Enter 3 for peek operaton");
printf("->Enter 4 for display operaton");
printf("=========================================================");
}
void push(){
int value=0,i=0;
if(top== size-1){
printf("Stack Overflow");
}
else{
top++;
printf("Enter your value:");
scanf("%d",&value);
stack[top] = value;
}
display();
}
void pop(){
int value=0;
if(top == -1){
printf("Stack is empty");
}
else{
value = stack[top];
top--;
printf("Poped value is %d",value);
}
display();
}
void peek(){
if(top == -1){
printf("Stack is empty");
}
else{
printf("%d", stcak[top]);
}
}
void display(){
if(top == -1){
printf("Stack is empty");
}
else{
for(i=top;i>=0;i--){
printf("%d", stack[i]);
}
}
}