mirror of
https://hub.njuu.cf/TheAlgorithms/Python.git
synced 2023-10-11 13:06:12 +08:00
Added front to indicate the starting of the Queue
Front variable is added so that dequeue can be done any number of times.Without front,it displays only self.entries[0] as dequeued.
This commit is contained in:
parent
f5fc930c1b
commit
7e26755140
@ -3,6 +3,7 @@ class Queue():
|
||||
def __init__(self):
|
||||
self.entries = []
|
||||
self.length = 0
|
||||
self.front=0
|
||||
|
||||
def __str__(self):
|
||||
printed = '<' + str(self.entries)[1:-1] + '>'
|
||||
@ -22,8 +23,9 @@ class Queue():
|
||||
item that was dequeued"""
|
||||
def get(self):
|
||||
self.length = self.length - 1
|
||||
dequeued = self.entries[0]
|
||||
self.entries = self.entries[1:]
|
||||
dequeued = self.entries[self.front]
|
||||
self.front-=1
|
||||
self.entries = self.entries[self.front:]
|
||||
return dequeued
|
||||
|
||||
"""Rotates the queue {@code rotation} times
|
||||
|
Loading…
Reference in New Issue
Block a user