-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Nourhan - Spruce - C16 #50
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,39 +23,58 @@ def enqueue(self, element): | |
In the store are occupied | ||
returns None | ||
""" | ||
pass | ||
if self.size == INITIAL_QUEUE_SIZE: | ||
raise QueueFullException() | ||
index = self.rear % self.buffer_size | ||
self.store[index] = element | ||
self.rear -= 1 | ||
self.size += 1 | ||
Comment on lines
+28
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting to decrease the rear pointer instead of increasing it! 😎 |
||
|
||
def dequeue(self): | ||
""" Removes and returns an element from the Queue | ||
Raises a QueueEmptyException if | ||
The Queue is empty. | ||
""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✨ |
||
pass | ||
if self.size == 0: | ||
raise QueueEmptyException() | ||
index = self.front % self.buffer_size | ||
element = self.store[index] | ||
self.front -= 1 | ||
self.size -= 1 | ||
return element | ||
|
||
def front(self): | ||
""" Returns an element from the front | ||
of the Queue and None if the Queue | ||
is empty. Does not remove anything. | ||
""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✨ |
||
pass | ||
if self.size == 0: | ||
return None | ||
index = self.front % self.buffer_size | ||
return self.store[index] | ||
|
||
|
||
def size(self): | ||
""" Returns the number of elements in | ||
The Queue | ||
""" | ||
pass | ||
return self.size | ||
|
||
def empty(self): | ||
""" Returns True if the Queue is empty | ||
And False otherwise. | ||
""" | ||
pass | ||
return self.size == 0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✨ |
||
|
||
def __str__(self): | ||
""" Returns the Queue in String form like: | ||
[3, 4, 7] | ||
Starting with the front of the Queue and | ||
ending with the rear of the Queue. | ||
""" | ||
pass | ||
result = [] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✨ |
||
for index in range(self.front, self.front - self.size, -1): | ||
result.append(self.store[index % self.buffer_size]) | ||
return str(result) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,27 +12,36 @@ def push(self, element): | |
""" Adds an element to the top of the Stack. | ||
Returns None | ||
""" | ||
pass | ||
self.store.add_last(element) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✨ |
||
|
||
def pop(self): | ||
""" Removes an element from the top | ||
Of the Stack | ||
Raises a StackEmptyException if | ||
The Stack is empty. | ||
returns None | ||
returns the removed element | ||
""" | ||
pass | ||
if self.empty(): | ||
raise StackEmptyException() | ||
|
||
return self.store.remove_last() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✨ |
||
|
||
|
||
def empty(self): | ||
""" Returns True if the Stack is empty | ||
And False otherwise | ||
""" | ||
pass | ||
return self.store.empty() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✨ |
||
|
||
def __str__(self): | ||
""" Returns the Stack in String form like: | ||
[3, 4, 7] | ||
Starting with the top of the Stack and | ||
ending with the bottom of the Stack. | ||
""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✨ This does work, but you could also take advantage of the |
||
pass | ||
values = [] | ||
|
||
current = self.store.get_last() | ||
while current: | ||
values.append(str(current.value)) | ||
current = current.prev |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest using
buffer_size
overINITIAL_QUEUE_SIZE
here. Imagine you alter your implementation so that thebuffer_size
could expand in certain cases. Then you would have to manually change all of your references toINITIAL_QUEUE_SIZE
to maintain your code.