-
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?
Conversation
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.
✨😎 Nice work, Nourhan. I left some small suggestions, but overall you have a very solid and unique implementation. Let me know what questions you have.
🟢
@@ -23,39 +23,58 @@ def enqueue(self, element): | |||
In the store are occupied | |||
returns None | |||
""" | |||
pass | |||
if self.size == INITIAL_QUEUE_SIZE: |
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
over INITIAL_QUEUE_SIZE
here. Imagine you alter your implementation so that the buffer_size
could expand in certain cases. Then you would have to manually change all of your references to INITIAL_QUEUE_SIZE
to maintain your code.
if self.size == INITIAL_QUEUE_SIZE: | |
if self.size == self.buffer_size: |
index = self.rear % self.buffer_size | ||
self.store[index] = element | ||
self.rear -= 1 | ||
self.size += 1 |
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.
Interesting to decrease the rear pointer instead of increasing it! 😎
index = self.rear % self.buffer_size | ||
self.store[index] = element | ||
self.rear -= 1 | ||
self.size += 1 | ||
|
||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
✨
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 comment
The reason will be displayed to describe this comment to others. Learn more.
✨
|
||
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
✨
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
✨
if self.empty(): | ||
raise StackEmptyException() | ||
|
||
return self.store.remove_last() |
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.
✨
|
||
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 comment
The 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() | ||
|
||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
✨ This does work, but you could also take advantage of the str
method in the LinkedList
class
Stacks and Queues
Thanks for doing some brain yoga. You are now submitting this assignment!
Comprehension Questions
OPTIONAL JobSimulation