class Queue:
def __init__(self, *array):
self.array = []
for el in array:
self.array.append(el)
def __str__(self):
string = ['[']
for el in self.array:
string.append(str(el))
string.append(' -> ')
del string[-1]
string.append(']')
string = ''.join(string)
return string
def next(self):
new_array = self.array[1::]
return Queue(*new_array)
q1 = Queue(1, 2, 3, 4)
q2 = q1.next()
q3 = next(q1)
print(q1)
print(q2)
print(q3)
class Queue:
def __init__(self, *array):
self.array = []
for el in array:
self.array.append(el)
self.generator = self.__gen()
def __str__(self):
string = ['[']
for el in self.array:
string.append(str(el))
string.append(' -> ')
del string[-1]
string.append(']')
string = ''.join(string)
return string
def next(self):
new_array = self.array[1::]
return Queue(*new_array)
def __gen(self):
l = len(self.array)
for i in range(1,l):
new_array = self.array[i:]
yield Queue(*new_array)
def __next__(self):
try:
n = next(self.generator)
except StopIteration:
n = None
return n
q1 = Queue(1, 2, 3, 4)
q2 = q1.next()
print(q1)
print(q2)
q3 = next(q1)
print(q3)
q3 = next(q1)
print(q3)
q3 = next(q1)
print(q3)
q3 = next(q1)
print(q3)