Skip to content

Commit

Permalink
Added toString and rotate
Browse files Browse the repository at this point in the history
  • Loading branch information
ShyamW committed Oct 9, 2016
1 parent 78f99d2 commit 13dd4a1
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions data_structures/QueueOnList.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ def __init__(self):
self.entries = []
self.length = 0

def __str__(self):
printed = '<' + str(self.entries)[1:-1] + '>'
return printed

"""Enqueues {@code item}
@param item
item to enqueue"""
def put(self, item):
self.entries.append(item)
self.length = self.length + 1
print(self.entries)


"""Dequeues {@code item}
@requirement: |self.length| > 0
Expand All @@ -22,6 +26,13 @@ def get(self):
self.entries = self.entries[1:]
return dequeued

"""Rotates the queue {@code rotation} times
@param rotation
number of times to rotate queue"""
def rotate(self, rotation):
for i in range(rotation):
self.put(self.get())

"""Enqueues {@code item}
@return item at front of self.entries"""
def front(self):
Expand All @@ -30,6 +41,3 @@ def front(self):
"""Returns the length of this.entries"""
def size(self):
return self.length



0 comments on commit 13dd4a1

Please sign in to comment.