Advertisement
1nikitas

Untitled

Mar 27th, 2022
1,052
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.41 KB | None | 0 0
  1. class Queue:
  2.     def __init__(self, *values):
  3.         self.nums = []
  4.         for i in values:
  5.             self.nums.append(i)
  6.  
  7.     def append(self, *values):
  8.         for i in values:
  9.             self.nums.append(i)
  10.  
  11.     def copy(self):
  12.         new = Queue()
  13.         new.nums += self.nums
  14.         return new
  15.  
  16.     def pop(self):
  17.         if self.nums:
  18.             first = self.nums[0]
  19.             del self.nums[0]
  20.             return first
  21.  
  22.     def extend(self, queue):
  23.         self.nums += queue.nums
  24.  
  25.     def next(self):
  26.         new = self.copy()
  27.         new.nums = new.nums[1:]
  28.         return new
  29.  
  30.     def __rshift__(self, n):
  31.         if len(self.nums) > n:
  32.             new = Queue()
  33.             new.nums += self.nums[n:]
  34.             return new
  35.         return Queue()
  36.  
  37.     def __add__(self, other):
  38.         new = self.copy()
  39.         new.nums += other.nums
  40.         return new
  41.  
  42.     def __iadd__(self, other):
  43.         self.nums += other.nums
  44.         return self
  45.  
  46.     def __eq__(self, other):
  47.         if self.nums == other.nums:
  48.             return True
  49.         return False
  50.  
  51.     def __str__(self):
  52.         if self.nums:
  53.             self.nums = list(map(str, self.nums))
  54.             nums = ' -> '.join(self.nums)
  55.             return f'[{nums}]'
  56.         return '[]'
  57.        
  58.     def __next__(queue):
  59.         new = queue.copy()
  60.         new.nums = new.nums[1:]
  61.         return new
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement