Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Queue:
- def __init__(self, *values):
- self.nums = []
- for i in values:
- self.nums.append(i)
- def append(self, *values):
- for i in values:
- self.nums.append(i)
- def copy(self):
- new = Queue()
- new.nums += self.nums
- return new
- def pop(self):
- if self.nums:
- first = self.nums[0]
- del self.nums[0]
- return first
- def extend(self, queue):
- self.nums += queue.nums
- def next(self):
- new = self.copy()
- new.nums = new.nums[1:]
- return new
- def __rshift__(self, n):
- if len(self.nums) > n:
- new = Queue()
- new.nums += self.nums[n:]
- return new
- return Queue()
- def __add__(self, other):
- new = self.copy()
- new.nums += other.nums
- return new
- def __iadd__(self, other):
- self.nums += other.nums
- return self
- def __eq__(self, other):
- if self.nums == other.nums:
- return True
- return False
- def __str__(self):
- if self.nums:
- self.nums = list(map(str, self.nums))
- nums = ' -> '.join(self.nums)
- return f'[{nums}]'
- return '[]'
- def __next__(queue):
- new = queue.copy()
- new.nums = new.nums[1:]
- return new
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement