Skip to content

Commit 6997062

Browse files
committed
Restructured folder/files
1 parent b29b6d3 commit 6997062

File tree

35 files changed

+1113
-1113
lines changed

35 files changed

+1113
-1113
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,151 +1,151 @@
1-
//2 stacks in an array
2-
#include<bits/stdc++.h>
3-
using namespace std ;
4-
class TwoStacks
5-
{
6-
int *arr ;
7-
int size ;
8-
int top1 ;
9-
int top2 ;
10-
public:
11-
TwoStacks()
12-
{
13-
this->size = 6 ;
14-
arr = new int[6] ;
15-
top1 = -1 ;
16-
top2 = 6 ;
17-
}
18-
void push1(int data)
19-
{
20-
if(top1 < top2-1)
21-
{
22-
top1++ ;
23-
arr[top1] = data ;
24-
}
25-
else
26-
{
27-
cout<<"Stack1 Over-Flow"<<endl ;
28-
}
29-
}
30-
void push2(int data)
31-
{
32-
if(top1 < top2-1)
33-
{
34-
top2-- ;
35-
arr[top2] = data ;
36-
}
37-
else
38-
{
39-
cout<<"Stack2 Over-Flow"<<endl ;
40-
}
41-
}
42-
void pop1()
43-
{
44-
if(top1>=0)
45-
{
46-
top1-- ;
47-
}
48-
else
49-
{
50-
cout<<"Stack1 Under-Flow"<<endl ;
51-
}
52-
}
53-
void pop2()
54-
{
55-
if(top2<size)
56-
{
57-
top2++ ;
58-
}
59-
else
60-
{
61-
cout<<"Stack2 Under-Flow"<<endl ;
62-
}
63-
}
64-
int top_elem_1()
65-
{
66-
if(top1>=0)
67-
{
68-
return arr[top1];
69-
}
70-
else
71-
{
72-
cout<<"Stack1 Under-Flow"<<endl ;
73-
return -1 ;
74-
}
75-
}
76-
int top_elem_2()
77-
{
78-
if(top2<size)
79-
{
80-
return arr[top2];
81-
}
82-
else
83-
{
84-
cout<<"Stack2 Under-Flow"<<endl ;
85-
return -1 ;
86-
}
87-
}
88-
bool isEmpty_1()
89-
{
90-
if(top1<0)
91-
return true ;
92-
else
93-
return false ;
94-
}
95-
bool isEmpty_2()
96-
{
97-
if(top2>=size)
98-
return true ;
99-
else
100-
return false ;
101-
}
102-
int size_1()
103-
{
104-
if(top1<0)
105-
{
106-
cout<<"Stack1 Under-Flow"<<endl ;
107-
return -1;
108-
}
109-
else
110-
{
111-
return top1+1 ;
112-
}
113-
}
114-
int size_2()
115-
{
116-
if(top2>=size)
117-
{
118-
cout<<"Stack2 Under-Flow"<<endl ;
119-
return -1;
120-
}
121-
else
122-
{
123-
return size-top2 ;
124-
}
125-
}
126-
};
127-
int main()
128-
{
129-
TwoStacks ts ;
130-
ts.push1(1);
131-
ts.push1(2);
132-
ts.push2(6);
133-
ts.push1(3);
134-
ts.push2(5);
135-
ts.push1(4);
136-
cout<<"Top in Stack 1 : "<<ts.top_elem_1()<<endl ;
137-
ts.pop1() ;
138-
cout<<"Top in Stack 1 : "<<ts.top_elem_1()<<endl ;
139-
cout<<"Top in Stack 2 : "<<ts.top_elem_2()<<endl ;
140-
ts.push2(10);
141-
cout<<"Top in Stack 2 : "<<ts.top_elem_2()<<endl ;
142-
ts.push1(3) ;
143-
ts.pop1();
144-
ts.pop1();
145-
ts.pop1();
146-
ts.pop2();
147-
ts.pop2();
148-
ts.pop2();
149-
ts.pop1();
150-
ts.pop2();
151-
}
1+
//2 stacks in an array
2+
#include<bits/stdc++.h>
3+
using namespace std ;
4+
class TwoStacks
5+
{
6+
int *arr ;
7+
int size ;
8+
int top1 ;
9+
int top2 ;
10+
public:
11+
TwoStacks()
12+
{
13+
this->size = 6 ;
14+
arr = new int[6] ;
15+
top1 = -1 ;
16+
top2 = 6 ;
17+
}
18+
void push1(int data)
19+
{
20+
if(top1 < top2-1)
21+
{
22+
top1++ ;
23+
arr[top1] = data ;
24+
}
25+
else
26+
{
27+
cout<<"Stack1 Over-Flow"<<endl ;
28+
}
29+
}
30+
void push2(int data)
31+
{
32+
if(top1 < top2-1)
33+
{
34+
top2-- ;
35+
arr[top2] = data ;
36+
}
37+
else
38+
{
39+
cout<<"Stack2 Over-Flow"<<endl ;
40+
}
41+
}
42+
void pop1()
43+
{
44+
if(top1>=0)
45+
{
46+
top1-- ;
47+
}
48+
else
49+
{
50+
cout<<"Stack1 Under-Flow"<<endl ;
51+
}
52+
}
53+
void pop2()
54+
{
55+
if(top2<size)
56+
{
57+
top2++ ;
58+
}
59+
else
60+
{
61+
cout<<"Stack2 Under-Flow"<<endl ;
62+
}
63+
}
64+
int top_elem_1()
65+
{
66+
if(top1>=0)
67+
{
68+
return arr[top1];
69+
}
70+
else
71+
{
72+
cout<<"Stack1 Under-Flow"<<endl ;
73+
return -1 ;
74+
}
75+
}
76+
int top_elem_2()
77+
{
78+
if(top2<size)
79+
{
80+
return arr[top2];
81+
}
82+
else
83+
{
84+
cout<<"Stack2 Under-Flow"<<endl ;
85+
return -1 ;
86+
}
87+
}
88+
bool isEmpty_1()
89+
{
90+
if(top1<0)
91+
return true ;
92+
else
93+
return false ;
94+
}
95+
bool isEmpty_2()
96+
{
97+
if(top2>=size)
98+
return true ;
99+
else
100+
return false ;
101+
}
102+
int size_1()
103+
{
104+
if(top1<0)
105+
{
106+
cout<<"Stack1 Under-Flow"<<endl ;
107+
return -1;
108+
}
109+
else
110+
{
111+
return top1+1 ;
112+
}
113+
}
114+
int size_2()
115+
{
116+
if(top2>=size)
117+
{
118+
cout<<"Stack2 Under-Flow"<<endl ;
119+
return -1;
120+
}
121+
else
122+
{
123+
return size-top2 ;
124+
}
125+
}
126+
};
127+
int main()
128+
{
129+
TwoStacks ts ;
130+
ts.push1(1);
131+
ts.push1(2);
132+
ts.push2(6);
133+
ts.push1(3);
134+
ts.push2(5);
135+
ts.push1(4);
136+
cout<<"Top in Stack 1 : "<<ts.top_elem_1()<<endl ;
137+
ts.pop1() ;
138+
cout<<"Top in Stack 1 : "<<ts.top_elem_1()<<endl ;
139+
cout<<"Top in Stack 2 : "<<ts.top_elem_2()<<endl ;
140+
ts.push2(10);
141+
cout<<"Top in Stack 2 : "<<ts.top_elem_2()<<endl ;
142+
ts.push1(3) ;
143+
ts.pop1();
144+
ts.pop1();
145+
ts.pop1();
146+
ts.pop2();
147+
ts.pop2();
148+
ts.pop2();
149+
ts.pop1();
150+
ts.pop2();
151+
}

0 commit comments

Comments
 (0)