PY
py
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
#Queue using two Stacks
stack1 = []
stack2 = []
Q = int(input())
for i in range(Q):
user_input = input()
choice = int(user_input[:1])
if(choice == 1):
user_input = int(user_input[2:])
stack1.append(user_input)
elif(choice == 2):
for i in range(len(stack1)):
element = stack1.pop()
stack2.append(element)
stack2.pop()
for i in range(len(stack2)):
element = stack2.pop()
stack1.append(element)
elif(choice == 3):
print(stack1[0])
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run