-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2StacksInAnArrays.cpp
More file actions
49 lines (40 loc) · 856 Bytes
/
2StacksInAnArrays.cpp
File metadata and controls
49 lines (40 loc) · 856 Bytes
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
/*The structure of the class is
class twoStacks
{
int *arr;
int size;
int top1, top2;
public:
twoStacks(int n=100){size = n; arr = new int[n]; top1 = -1; top2 = size;}
void push1(int x);
void push2(int x);
int pop1();
int pop2();
};
*/
/* The method push to push element into the stack 2 */
void twoStacks :: push1(int x)
{
arr[++top1] = x;
}
/* The method push to push element into the stack 2*/
void twoStacks ::push2(int x)
{
arr[--top2] = x;
}
/* The method pop to pop element from the stack 1 */
//Return the popped element
int twoStacks ::pop1()
{
if(top1 == -1)
return -1;
return arr[top1--];
}
/* The method pop to pop element from the stack 2 */
//Return the popped element
int twoStacks :: pop2()
{
if(top2 == size)
return -1;
return arr[top2++];
}