mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-27 15:01:08 +00:00
Added Queue
This commit is contained in:
parent
df8798416b
commit
9b2d32e8a3
35
data_structures/QueueOnList.py
Normal file
35
data_structures/QueueOnList.py
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
"""Queue represented by a python list"""
|
||||||
|
class Queue():
|
||||||
|
def __init__(self):
|
||||||
|
self.entries = []
|
||||||
|
self.length = 0
|
||||||
|
|
||||||
|
"""Enqueues {@code item}
|
||||||
|
@param item
|
||||||
|
item to enqueue"""
|
||||||
|
def enqueue(self, item):
|
||||||
|
self.entries.append(item)
|
||||||
|
self.length = self.length + 1
|
||||||
|
print(self.entries)
|
||||||
|
|
||||||
|
"""Dequeues {@code item}
|
||||||
|
@requirement: |self.length| > 0
|
||||||
|
@return dequeued
|
||||||
|
item that was dequeued"""
|
||||||
|
def dequeue(self):
|
||||||
|
self.length = self.length - 1
|
||||||
|
dequeued = self.entries[0]
|
||||||
|
self.entries = self.entries[1:]
|
||||||
|
return dequeued
|
||||||
|
|
||||||
|
"""Enqueues {@code item}
|
||||||
|
@return item at front of self.entries"""
|
||||||
|
def front(self):
|
||||||
|
return self.entries[0]
|
||||||
|
|
||||||
|
"""Returns the length of this.entries"""
|
||||||
|
def length(self):
|
||||||
|
return self.length
|
||||||
|
|
||||||
|
|
||||||
|
|
0
other/anagrams.txt
Normal file
0
other/anagrams.txt
Normal file
Loading…
Reference in New Issue
Block a user