pass all test case for queues and stack assignment#40
pass all test case for queues and stack assignment#40Eatmine wants to merge 1 commit intoAda-C16:masterfrom
Conversation
There was a problem hiding this comment.
😎 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.
🟢
|
|
||
|
|
||
| def enqueue(self, element): |
| def dequeue(self): | ||
| """ Removes and returns an element from the Queue | ||
| Raises a QueueEmptyException if | ||
| The Queue is empty. |
| is empty. Does not remove anything. | ||
| """ | ||
| pass | ||
| if self.store[self.front]: |
There was a problem hiding this comment.
🤔 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(): |
| return None | ||
|
|
||
|
|
||
| def size(self): |
| if self.size == 0: | ||
| return True | ||
| else: | ||
| return False |
There was a problem hiding this comment.
Minor style suggestion to condense your code!
| if self.size == 0: | |
| return True | |
| else: | |
| return False | |
| return self.size == 0 |
| else: | ||
| return False | ||
|
|
||
| def __str__(self): |
| """ | ||
| pass | ||
|
|
||
| return self.store.add_first(element) |
| pass | ||
|
|
||
| if self.store.length() == 0: | ||
| return None |
There was a problem hiding this comment.
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.
Per the specification, you don't want to return anything!
| return self.store.remove_first() | |
| self.store.remove_first() |
| return self.store.remove_first() | ||
|
|
||
|
|
||
| def empty(self): |
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