-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStacks.c
More file actions
89 lines (87 loc) · 1.57 KB
/
Copy pathStacks.c
File metadata and controls
89 lines (87 loc) · 1.57 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
/******************************************************************************
Online C Compiler.
Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <stdio.h>
#include <stdbool.h>
#include<stdlib.h>
#define SIZE 10
int a[SIZE];
int top=-1;
bool isEmpty(){
if(top == -1){
return true;
}
return false;
}
bool isFull(){
if(top==10){
return true;
}
return false;
}
void pop(){
if(isEmpty()){
printf("Stack is empty\n");
return;
}
printf("%d\n",a[top]);
top -= 1;
}
void push(int value){
if(isFull()){
printf("Stack is full\n");
return;
}
top += 1;
a[top]=value;
}
void display(){
if(isEmpty()){
printf("Stack is empty\n");
return;
}
for(int i=top;i>=0;i--){
printf("%d ",a[i]);
}
}
int topelement(){
if(isEmpty()){
printf("Stack is empty\n");
return 1;
}
return a[top];
}
int input(){
int value;
printf("Enter the value\n");
scanf("%d",&value);
return value;
}
int main()
{
int ch,value;
while(true){
printf("Enter the operation to be done\n");
printf("1-Push 2-Pop 3-Display 4-TopElement 5-Exit\n");
scanf("%d",&ch);
switch(ch){
case 1:
value=input();
push(value);
break;
case 2:
pop();
break;
case 3:
display();
break;
case 4:
topelement();
break;
default:
exit(0);
}
}
}