-
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
pass all test case for queues and stack assignment #40
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 Min. I left a few comments and suggestions, but overall nice implementation. Let me know what questions you have.
For the difference between implementing something and using something, note that 'using something' doesn't necessarily mean using an API, it just means using code that someone else implemented. You could use an API, or it could be a library, module, or function someone else implemented.
🟢
@@ -15,47 +19,95 @@ def __init__(self): | |||
self.front = -1 | |||
self.rear = -1 | |||
self.size = 0 | |||
|
|||
|
|||
def enqueue(self, 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.
✨
|
||
|
||
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.
✨
|
||
def front(self): | ||
""" Returns an element from the front | ||
of the Queue and None if the Queue | ||
is empty. Does not remove anything. | ||
""" | ||
pass | ||
if self.store[self.front]: |
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.
🤔 Since you do not reassign None
as the value of whichever elements you dequeue in your dequeue
implementation, this conditional may evaluate to True
even when the queue is empty. I would suggest checking if your queue is empty to determine whether or not you should return the front element instead.
if self.store[self.front]: | |
if self.empty(): |
if self.store[self.front]: | ||
return self.front | ||
else: | ||
return None | ||
|
||
|
||
def size(self): |
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.size == 0: | ||
return True | ||
else: | ||
return False |
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.
Minor style suggestion to condense your code!
if self.size == 0: | |
return True | |
else: | |
return False | |
return self.size == 0 |
if self.size == 0: | ||
return True | ||
else: | ||
return False | ||
|
||
def __str__(self): |
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.
✨ Love the comments!
@@ -12,7 +12,10 @@ def push(self, element): | |||
""" Adds an element to the top of the Stack. | |||
Returns None | |||
""" | |||
pass | |||
|
|||
return self.store.add_first(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.
✨
pass | ||
|
||
if self.store.length() == 0: | ||
return None |
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.
Per the specification, you want to raise a StackEmptyException
here instead
if self.store.length() == 0: | ||
return None | ||
else: | ||
return self.store.remove_first() |
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.
Per the specification, you don't want to return anything!
return self.store.remove_first() | |
self.store.remove_first() |
return None | ||
else: | ||
return self.store.remove_first() | ||
|
||
|
||
def empty(self): |
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.
✨
Stacks and Queues
Thanks for doing some brain yoga. You are now submitting this assignment!
Comprehension Questions
| Describe a Queue | A queue opeerates in a first-in-first out order. The first element to enter the queue is the first el |
| What are the 5 methods in Queue and what does each do? | enqueue puts an item into the back of the queue. dequeue removes and returns the item at the front of the queue. Is_empty returns true if the queue is empty and false otherwise. Size, returns the number of the size in the queue. Front returns an element from the front of the Queue and None if the Queue is empty. |
| What is the difference between implementing something and using something? | Implementing is accomplishing or completing a task and using something means to call an API. |
OPTIONAL JobSimulation