-
Notifications
You must be signed in to change notification settings - Fork 0
/
combinedOperationsArray.c
97 lines (91 loc) · 1.85 KB
/
combinedOperationsArray.c
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
95
96
97
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#define Maximum 10
int stackArray[Maximum];
int top=-1;
int value;
bool isEmpty(stackArray){
if(top==-1){
return true;
}
else{
return false;
}
}
bool isFull(stackArray){
if(top==Maximum-1){
return true;
}
else{
return false;
}
}
void push(){
if(isFull()){
printf("Sorry!! Stack is already full\n");
}
else{
printf("Enter a value you want to insert..");
scanf("%d",&value);
top++;
stackArray[top]=value;
printf("Push done Successfully\n\n");
display();
}
}
void pop(){
int popp;
if(isEmpty()){
printf("Sorry!! Stack is Empty\n\n");
}
else{
popp=stackArray[top];
top--;
printf("You have Successfully popped an element from your Stack\n\n");
display();
free(popp);
}
}
void display(){
int i;
if(isEmpty()){
printf("Your Stack is Empty\n\n");
}
else{
printf("Your Stack is now having: %d elements below\n\n", top+1);
for(i=0;i<=top;i++){
printf("%d\t", stackArray[i]);
}
printf("\n\n");
}
}
void main(){
int choice;
printf("Welcome to our program!!!\n\n");
do {
printf(" Enter 1. To Push\n Enter 2. To Pop\n Enter 3. To Display Stack elements\n Enter 0 to exit\n\n");
printf("Enter your choice...");
scanf("%d", &choice);
switch(choice){
case 1:
printf("\n");
push();
break;
case 2:
printf("\n");
pop();
break;
case 3:
printf("\n");
display();
break;
case 0:
printf("Thank you for using our system. Bye!!\n\n");
return;
default:
printf("Sorry you entered invalid choice. Try Again!\n");
}
}
while(choice!=0);
}