-
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
Maple Monica C. #42
base: master
Are you sure you want to change the base?
Maple Monica C. #42
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 Monica! I left suggestions on your __str__
implementations for both Stack and Queue.
Re: Implementation vs Using, implementation doesn't necessarily mean you are using another 'thing' as in one data type to define another data type, just that you are writing the code to make a function or larger piece of code work yourself. You are correct, using just means you are using code other people wrote.
Let me know what questions you have.
🟢
|
||
def enqueue(self, element): | ||
""" Adds an element to the Queue | ||
Raises a QueueFullException if all elements | ||
In the store are occupied | ||
returns None | ||
""" | ||
pass | ||
|
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. | ||
""" | ||
pass |
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 | ||
return 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.
✨
def size(self): | ||
""" Returns the number of elements in | ||
The Queue | ||
""" | ||
pass | ||
return self.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.
✨
|
||
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 empty(self): | ||
""" Returns True if the Queue is empty | ||
And False otherwise. | ||
""" | ||
pass | ||
return self.size == 0 | ||
|
||
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. | ||
""" |
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.
👀 See comment below ⬇️
@@ -12,7 +12,7 @@ def push(self, element): | |||
""" Adds an element to the top of the Stack. | |||
Returns None | |||
""" | |||
pass | |||
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.
✨
@@ -21,18 +21,21 @@ def pop(self): | |||
The Stack is empty. | |||
returns 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.
✨
if self.store.empty(): | ||
raise StackEmptyException | ||
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.
✨
|
||
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. | ||
""" | ||
pass | ||
return self.store.__str__() |
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.
The __str__
method is an example of what we call operator overloading. Operator overloading is used for methods and operators such as str()
, ==
, and +
where Python actually has a predefined way it will attempt to do these operations or methods on any object or data type. Methods like __str__
, __eq__
, and __add__
allow us to either extend or overwrite the predefined functionality with our own desired functionality.
When we implement the function, we use the dunders around the function name (ex. __str__
) to indicate that we are about to do operator overloading. However, when we call the function, we can remove the dunders.
return self.store.__str__() | |
return str(self.store) |
Stacks and Queues
Thanks for doing some brain yoga. You are now submitting this assignment!
Comprehension Questions
OPTIONAL JobSimulation