Menu
×
×
Correct!
Exercise:How does the queue "peek" operation work?
class Queue:
def __init__(self):
self.queue = []
def enqueue(self, element):
self.queue.append(element)
def dequeue(self):
if self.isEmpty():
return "Queue is empty"
return self.queue.pop(0)
def peek(self):
if self.isEmpty():
return "Queue is empty"
return self.queue[@(1)]
def isEmpty(self):
return len(self.queue) == 0
def size(self):
return len(self.queue)
class Queue:
def __init__(self):
self.queue = []
def enqueue(self, element):
self.queue.append(element)
def dequeue(self):
if self.isEmpty():
return "Queue is empty"
return self.queue.pop(0)
def peek(self):
if self.isEmpty():
return "Queue is empty"
return self.queue[0]
def isEmpty(self):
return len(self.queue) == 0
def size(self):
return len(self.queue)
Not CorrectClick here to try again. Correct!Next ❯ |
This will reset the score of ALL 43 exercises.
Are you sure you want to continue?