From 13dd4a1e5d74b1262df6f37616f5fc91fe95520f Mon Sep 17 00:00:00 2001 From: Date: Sun, 9 Oct 2016 11:51:43 -0400 Subject: [PATCH] Added toString and rotate --- data_structures/QueueOnList.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/data_structures/QueueOnList.py b/data_structures/QueueOnList.py index c6c01f7c0235..3e1c79be1f47 100644 --- a/data_structures/QueueOnList.py +++ b/data_structures/QueueOnList.py @@ -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 @@ -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): @@ -30,6 +41,3 @@ def front(self): """Returns the length of this.entries""" def size(self): return self.length - - -