-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathStack.c
More file actions
71 lines (51 loc) · 1.11 KB
/
Stack.c
File metadata and controls
71 lines (51 loc) · 1.11 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
#include<stdio.h> //header file
#include<stdlib.h>
//Library
#define N 30
int stack[N],top = -1;
void push(int data){
if(top == N-1){
printf("Cannot insert the element, Stack overflow...");
return;
}
stack[++top] = data;
printf("Pushed successfully");
}
void pop(){
if(top == -1){
printf("Cannot perform pop operation, Stack underflow(Empty)");
return;
}
printf("The element poped out is %d",stack[top--]);
}
void peek(){
if(top == -1){
printf("Stack underflow, cannot peek into..");
return;
}
printf("The peek element is %d",stack[top]);
}
int main(){
int option;
char toContinue;
do{
printf("Operation to perform: \n");
printf("1. Push\n2. Pop\n3. Peek\n4. Exit\n");
scanf("%d",&option);
switch(option){
case 1: push();
break;
case 2: pop();
break;
case 3: peek();
break;
case 4: exit(0);
break;
default : printf("Invalid input key, try again...\n");
}
printf("Do you want to continue?(Y/N)");
fflush(stdin);
scanf("%c",&isContinue);
}while(c == 'Y' || c == 'y');
return 0;
}