-
Notifications
You must be signed in to change notification settings - Fork 0
/
DAY-10
44 lines (40 loc) · 832 Bytes
/
DAY-10
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
//Greek for greeks POTD --- Implement two stacks in an array
class twoStacks
{
int arr[];
int size;
int top1, top2;
twoStacks()
{
size = 100;
arr = new int[100];
top1 = -1;
top2 = size;
}
//Function to push an integer into the stack1.
void push1(int x)
{
top1++;
arr[top1] = x;
}
//Function to push an integer into the stack2.
void push2(int x)
{
top2--;
arr[top2] = x;
}
//Function to remove an element from top of the stack1.
int pop1()
{
if(top1==-1) return -1;
top1--;
return arr[top1+1];
}
//Function to remove an element from top of the stack2.
int pop2()
{
if(top2==size) return -1;
top2++;
return arr[top2-1];
}
}