fork download
  1. class Queue:
  2. def __init__(self):
  3. self.stack1 = []
  4. self.stack2 = []
  5.  
  6.  
  7. def push(self, x):
  8.  
  9. self.stack1.append(x)
  10.  
  11.  
  12. def pop(self):
  13.  
  14. if(len(self.stack2)) == 0:
  15. while len(self.stack1)>0:
  16. self.stack2.append(self.stack1.pop())
  17.  
  18. return self.stack2.pop()
  19.  
  20.  
  21. def peek(self):
  22. if(len(self.stack2)) == 0:
  23. while len(self.stack1)>0:
  24. self.stack2.append(self.stack1.pop())
  25.  
  26. return self.stack2[-1]
  27.  
  28.  
  29.  
  30. def empty(self):
  31. if len(self.stack1)==0 and len(self.stack2) == 0:
  32. return True
  33. else:
  34. return False
Success #stdin #stdout 0.04s 9696KB
stdin
Standard input is empty
stdout
Standard output is empty