-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2Stack in one array
96 lines (86 loc) · 1.81 KB
/
2Stack in one array
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
/*This Flie is Made by VISHESH YADAV (ECE-1) Netaji Subhas University Of technology*/
#include <stdio.h>
#define n 100
int top1=-1,top2=n,arr[n];
void push1(int val){
if(top1<top2-1){
arr[++top1]=val;
}
else{
printf("Stack is full\n");
}
}
void push2(int val){
if(top1<top2-1){
arr[--top2]=val;
}
else{
printf("Stack is full\n");
}
}
void pop1(){
if(top1>=0){
int popped_value= arr[top1--];
printf("%d has been popped\n",popped_value);
}
else{
printf("Stack is empty\n");
}
}
void pop2(){
if(top2<n){
int popped=arr[top2++];
printf("%d element popped\n",popped);
}
}
void display1(){
int i;
for(i=top1;i>=0;i--){
printf("%d ",arr[i]);
}
printf("\n");
}
void display2(){
int i;
for(i=top2;i<n;i++){
printf("%d ",arr[i]);
}
printf("\n");
}
int main(){
int val,ch;
while(1){
printf("Enter choice\n1.Insert in stack1\n2.Insert in stack2\n3.pop in stack1\n4.pop in stack2\n5.display stack1\n6.display stack2\n");
scanf("%d",&ch);
switch(ch){
case 1:{
printf("Enter element to push: ");
scanf("%d",&val);
push1(val);
break;
}
case 2:{
printf("Enter element to push: ");
scanf("%d",&val);
push2(val);
break;
}
case 3 : {
pop1();
break;
}
case 4:{
pop2();
break;
}
case 5:{
display1();
break;
}
case 6:{
display2();
}
default:printf("Invalid!\n");
}
}
}