Given a Queue Q containing N elements. The task is to reverse the Queue. Your task is to complete the function rev(), that reverses the N elements of the queue.
Example 1:
Input:
6
4 3 1 10 2 6
Output: 
6 2 10 1 3 4
Explanation: 
After reversing the given elements of the queue , the resultant queue will be 6 2 10 1 3 4.
Example 2:
Input:
4
4 3 2 1 
Output: 
1 2 3 4
Explanation: 
After reversing the given elements of the queue , the resultant queue will be 1 2 3 4.
Your Task: You need to complete the function rev that takes a queue as parameter and returns the reversed queue. The printing is done automatically by the driver code.
Expected Time Complexity : O(n)
Expected Auxilliary Space : O(n)
Constraints:
1 ≤ N ≤ 10^{5}
1 ≤ elements of Queue ≤ 10^{5}

Source: geeksforgeeks | Difficulty: EASY
Tags: Data structures

Starter code: #User function Template for python3



class Solution:

    #Function to reverse the queue.

    def rev(self, q):

        #add code here

Solutions:
def rev(q):
	stack = []
	while q.qsize() != 0:
		stack.append(q.get())
	while stack:
		q.put(stack.pop())
	return q


def rev(q):
	b = []
	while q.qsize():
		b.append(q.get())
	while len(b):
		q.put(b.pop())
	return q


def rev(q):
	queue = []
	while q.qsize() != 0:
		queue.append(q.get())
	n = len(queue)
	for i in range(n):
		q.put(queue[n - i - 1])
	return q


def rev(q):
	s = []
	while not q.empty():
		s.append(q.queue[0])
		q.get()
	while len(s) != 0:
		q.put(s[-1])
		s.pop()
	return q


def rev(q):
	st = []
	while q.qsize():
		st.append(q.get())
	while st:
		q.put(st.pop())
	return q


def rev(q):
	res = []
	while q.qsize():
		res.append(q.get())
	while len(res):
		q.put(res.pop())
	return q


def rev(q):
	stack = []
	while q.qsize():
		x = q.get()
		stack.append(x)
	while len(stack) > 0:
		q.put(stack[-1])
		stack.pop()
	return q


def rev(q):
	s = []
	for i in range(n):
		s.append(q.get())
	for i in range(n):
		q.put(s.pop())
	return q


def rev(q):
	st = []
	while q.qsize() != 0:
		st.append(q.get())
	while len(st) != 0:
		q.put(st.pop())
	return q


def rev(q):
	sol = []
	while not q.empty():
		sol.append(q.get())
	while len(sol) != 0:
		q.put(sol.pop())
	return q


def rev(q):
	q1 = []
	for i in range(q.qsize()):
		q1.append(q.get())
	n = len(q1) - 1
	for i in range(len(q1)):
		q.put(q1[n - i])
	return q


def rev(q):
	c = []
	while not q.empty():
		c.append(q.get())
	for j in c[::-1]:
		q.put(j)
	return q


def rev(q):
	stk = []
	while not q.empty():
		stk.append(q.get())
	while stk:
		q.put(stk.pop())
	return q


import queue

def rev(q: queue):
	n = q.qsize()
	stack = queue.LifoQueue(n)
	while not q.empty():
		stack.put(q.get())
	return stack


def rev(q):
	l = []
	a = Queue(maxsize=q.qsize())
	for i in range(q.qsize()):
		l.insert(0, q.get())
	for i in l:
		a.put(i)
	return a


def rev(q):
	list = []
	for i in range(q.qsize()):
		list.append(q.get())
	list.reverse()
	for i in list:
		q.put(i)
	return q


def rev(q):
	stack = []
	while not q.empty():
		stack.append(q.get())
	for i in range(len(stack) - 1, -1, -1):
		q.put(stack[i])
	return q


def rev(q):
	temp = []
	q_size = q.qsize()
	for i in range(q_size):
		cur = q.get()
		temp.insert(0, cur)
	for i in range(q_size):
		q.put(temp[i])
	return q


def rev(q):
	s = []
	while q.qsize() != 0:
		t = q.get()
		s.append(t)
	while len(s) != 0:
		n = len(s)
		t = s[n - 1]
		s.pop(n - 1)
		q.put(t)
	return q


def rev(q):
	lis = []
	for i in range(q.qsize()):
		lis.append(q.get())
	lis.reverse()
	q.empty()
	for i in lis:
		q.put(i)
	return q


def rev(q):
	stack = []
	while not q.empty():
		stack.append(q.get())
	while len(stack) > 0:
		q.put(stack[-1])
		stack.pop()
	return q


def rev(q):
	stack = []
	while q._qsize() != 0:
		x = q.get()
		stack.append(x)
	while stack:
		y = stack.pop()
		q.put(y)
	return q


import queue

def rev(q):
	l = []
	n = q.qsize()
	for i in range(0, n):
		k = q.get()
		l.append(k)
	l = l[::-1]
	z = Queue(maxsize=n)
	for i in l:
		z.put(i)
	return z


from queue import Queue

def rev(q):
	stk = []
	n = q.qsize()
	while q.qsize() != 0:
		stk.append(q.get())
	while len(stk) != 0:
		q.put(stk.pop())
	return q


def rev(q):
	l = []
	while not q.empty():
		num = q.get()
		l.append(num)
	while l:
		num = l.pop()
		q.put(num)
	return q


import queue

def rev(q):
	stack = []
	while q.qsize() != 0:
		stack.append(q.get())
	while len(stack) != 0:
		q.put(stack.pop())
	return q


def rev(q):
	store = []
	while q.qsize() != 0:
		store.append(q.get())
	for i in range(len(store) - 1, -1, -1):
		q.put(store[i])
	return q


def rev(q):
	new = []
	for i in range(q.qsize()):
		new.append(q.get())
	for i in range(len(new) - 1, -1, -1):
		q.put(new[i])
	return q


def rev(q):
	st = []
	while not q.empty():
		st.append(q.get())
	while st:
		q.put(st.pop())
	return q


def rev(q):
	reversal = []
	while not q.empty():
		front = q.get()
		reversal.append(front)
	while len(reversal) != 0:
		top = reversal.pop()
		q.put(top)
	return q


import queue

def rev(q):
	s = []
	while not q.empty():
		s.append(q.get())
	new = queue.Queue()
	while s:
		new.put(s.pop())
	return new


from sys import setrecursionlimit
setrecursionlimit(10 ** 5)

def rev(q):
	if q.empty():
		return
	front = q.get()
	rev(q)
	q.put(front)
	return q


from queue import Queue

def rev(q):
	if q.empty():
		return q
	stack = []
	while not q.empty():
		stack.append(q.get())
	while stack:
		q.put(stack.pop())
	return q


def rev(q):
	s = []
	while not q.empty():
		s.append(q.get(0))
	while s:
		q.put(s.pop())
	return q


def rev(q):
	s = []
	while q.empty() == False:
		s.append(q.get())
	while len(s) > 0:
		q.put(s.pop())
	return q


def rev(q):
	i = 0
	b = []
	while i < n:
		b.append(q.get(i))
		i += 1
	j = 0
	for i in reversed(b):
		q.put(i)
		j += 1
	return q


from collections import deque

def rev(q):
	stack = []
	while q.qsize() != 0:
		x = q.get()
		stack.append(x)
	while len(stack) != 0:
		x = stack.pop()
		q.put(x)
	return q


def rev(q):
	stack = []
	while not q.empty():
		stack.append(q.get())
	while stack:
		q.put(stack.pop())
	return q


def rev(q):
	t = q.qsize()
	temp = []
	for i in range(t):
		temp.append(q.get())
	while len(temp) != 0:
		q.put(temp.pop())
	return q


def rev(q):
	queue = []
	while not q.empty():
		queue.append(q.get(0))
	while len(queue) != 0:
		top = queue.pop()
		q.put(top)
	return q


from queue import LifoQueue

def rev(q):
	stack = LifoQueue(maxsize=q.qsize())
	while not q.empty():
		stack.put(q.get())
	return stack


from queue import Queue

def rev(q):
	l = []
	n = q.qsize()
	for a in range(n):
		l.append(q.get())
	l.reverse()
	for a in l:
		q.put(a)
	return q


def rev(q):
	a = []
	while q.qsize():
		a.append(q.get())
	while len(a):
		q.put(a.pop())
	return q


def rev(q):
	s = []
	l = q.qsize()
	for i in range(l):
		val = q.get()
		s.append(val)
	for i in range(l):
		val = s.pop()
		q.put(val)
	return q


def rev(q):
	l = []
	for i in range(q.qsize()):
		l.append(q.get())
	while l:
		q.put(l.pop())
	return q


def rev(q):
	stack = []
	while len(q.queue):
		data = q.queue.pop()
		stack.append(data)
	while len(stack):
		data = stack.pop()
		q.queue.appendleft(data)
	return q


def rev(q):
	arr = []
	for i in range(n):
		a = q.get()
		arr.insert(0, a)
	for i in arr:
		q.put(i)
	return q


def rev(q):
	arr = []
	while q.empty() != True:
		arr.append(q.get())
	arr.reverse()
	for i in range(0, len(arr)):
		q.put(arr[i])
	return q


def rev(q):
	q1 = []
	x = q.qsize()
	for i in range(x):
		q1.append(q.get())
	for j in range(len(q1) - 1, -1, -1):
		q.put(q1[j])
	return q