I have a very tough question here: how to build a LIFO stack using only FIFO queues ?
So I already have most of the code,but as you can see below ,I don't know how to code the pop function
import queue
class MyLifo:
def __init__(self):
self.fifo = queue.Queue();
self.fifoAux = queue.Queue();
def isEmpty(self):
return self.fifo.empty()
def push(self, x):
self.fifo.put(x)
def pop(self):
### your code here.
### for testing the solution:
lifo = MyLifo()
i=0
while (i<30):
lifo.push(i)
i+=1
while (lifo.isEmpty() == False):
print(lifo.pop())
lifo.push(3)
lifo.push(5)
print(lifo.pop())
lifo.push(30)
print(lifo.pop())
print(lifo.pop())
print(lifo.pop())
Any friend can help?