Advertisement
WupEly

Untitled

Apr 27th, 2023
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. from copy import copy
  2.  
  3. class Queue:
  4. def __init__(self, *values):
  5. self.q = list(values)
  6.  
  7. def __str__(self):
  8. q = ' -> '.join(map(str, self.q))
  9. return f'[{q}]'
  10.  
  11. def __next__(self):
  12. n = self.q[1:]
  13. return Queue(*n)
  14.  
  15. def __eq__(self, other):
  16. return self.q[:] == other.q[:]
  17.  
  18. def __add__(self, other):
  19. return copy(Queue(*(self.q + other.q)))
  20.  
  21. def __rshift__(self, other):
  22. n = self.q[other:]
  23. return Queue(*n)
  24.  
  25. def __iadd__(self, other):
  26. return Queue(*(self.q + other.q))
  27.  
  28. def extend(self, queue):
  29. self.q.extend(queue.q)
  30.  
  31. def append(self, *values):
  32. self.q += list(values)
  33.  
  34. def copy(self):
  35. return Queue(*self.q)
  36.  
  37. def pop(self):
  38. return self.q.pop(0)
  39.  
  40. def next(self):
  41. n = self.q[1:]
  42. return Queue(*n)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement