-
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
Tanya – Pine #37
base: master
Are you sure you want to change the base?
Tanya – Pine #37
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! I left one comment down below. Let me know what questions you have.
🟢
@@ -15,47 +15,81 @@ 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.
✨
self.rear = (self.rear + 1) % self.buffer_size | ||
self.store[self.rear] = element | ||
self.size += 1 | ||
return None | ||
|
||
def dequeue(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.
✨
self.front = (self.front + 1) % self.buffer_size | ||
self.size -= 1 | ||
return temp | ||
|
||
|
||
def front(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 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.front | ||
|
||
|
||
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.
✨
|
||
|
||
def size(self): | ||
""" Returns the number of elements in | ||
The Queue | ||
""" | ||
pass | ||
return self.size | ||
|
||
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.
✨
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.
✨
@@ -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.
✨
@@ -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) | |||
|
|||
def pop(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.
✨
@@ -21,18 +21,19 @@ def pop(self): | |||
The Stack is empty. | |||
returns None | |||
""" | |||
pass | |||
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.
Defining the __str__
method in a class is what we call operator overloading -- Python will convert any object to a string with the str() method by default, but it may not always be what we want. By defining the __str__
method, we can overwrite Python's default behavior to behavior that we want. However, when we call the overloaded method on an instance of the class, we do not need the dunders, we can just say str(object_instance)
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