Dada la clase Queue
implementar un método maximo
que no reciba ningún parámetro y que devuelva el valor máximo almacenado en la cola. Si la cola está vacía, devolverá None
.
class Node:
def __init__(self, value, next=None):
self.value = value
self.next = next
class Queue:
def __init__(self):
self._head = None
self._last = None
self._size = 0
def enqueue(self,value):
newnode = Node(value)
if self._head is None:
self._head = newnode
else:
self._last.next = newnode
self._last = newnode
self._size += 1
def dequeue(self):
if self.isEmpty():
raise IndexError("dequeue from empty queue")
returned = self._head.value
self._head = self._head.next
if self._head is None:
self._last = None
self._size -= 1
return returned
Mi código :
def maximo(self):
if len(self._head(value) > self._last(value)) :
return value
else :
None