Guest User

Untitled

a guest
Nov 21st, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. """
  2. Stack and Queue being implemented with Python List.
  3.  
  4. Both structures follow the design below:
  5. Bottom -> [...] -> Top.
  6. """
  7.  
  8. def dequeue(array: list) -> int:
  9. return array.pop()
  10.  
  11.  
  12. def empty_one_fill_the_other(stack1: list, stack2:list):
  13. while len(stack1) > 0:
  14. value = stack1.pop()
  15. stack2.append(value)
  16.  
  17. return stack2
  18.  
  19. def main():
  20. stck_one = [1,2,3]
  21. stck_two = []
  22.  
  23. queue = empty_one_fill_the_other(stck_one, stck_two)
  24. # After this, we should re do the same step in the other
  25. # direction, to keep the initial state intact.
  26.  
  27. # Should be equal to 1.
  28. print(dequeue(queue))
  29.  
  30.  
  31. if __name__ == "__main__":
  32. main()
Add Comment
Please, Sign In to add comment