-
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
Lety Palomo -Pine C-16 queue and stack project #57
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.
💫Hi Lety, your implementations were largely solid, but I did leave a few comments for you to take a look at.
For the comprehension questions. I'm looking for a bit more in the definition of an ADT. An abstract data type is a data type is defined by its behavior rather than its implementation.
A stack's five methods do include push
, pop
, and is_empty
like you mentioned, but rather than is_full
they also may include peek
and size
.
For a queue, the five methods are going to be enqueue
, dequeue
, is_empty
, front
, and rear
.
Using something does get you the benefits of something that's already created, you're correct, but we reap those benefits by say, calling a function someone else implemented or importing a library. Implementing is not so much applying something, but writing the code yourself.
Let me know what questions you have.
🟢
self.rear = 0 | ||
|
||
#per the test, don't duplicate the item if it was just enqueued | ||
if self.store[(self.rear - 1 ) % self.buffer_size] != 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.
🤔 I'm curious which test caused you to add this clause here. It shouldn't be necessary
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 went through lots of iterations to debug the tests. This is leftovers lol!
@@ -23,39 +23,88 @@ def enqueue(self, element): | |||
In the store are occupied | |||
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[(self.rear - 1 ) % self.buffer_size] != element: | ||
self.store[self.rear] = element | ||
self.rear = (self.rear + 1 ) % self.buffer_size | ||
self.size = 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.
✨
|
||
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.
✨
if self.size == 0: | ||
return True | ||
else: | ||
return False | ||
|
||
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.
✨
@@ -12,7 +15,8 @@ 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.
✨
if self.store.length == 0: | ||
raise StackEmptyException ("stack is empty") | ||
|
||
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.
✨
self.store.length = 0 | ||
if self.store.length == 0: | ||
return True | ||
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.
🤔 I'm not sure this works... it will always return True
since you set the length to 0 on line 37.
self.store.length = 0 | |
if self.store.length == 0: | |
return True | |
return False | |
if self.store.length == 0: | |
return True | |
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.
Good catch, thanks!
|
||
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. The str
method is built-in for all data types (even classes you create) in Python. When we want the str
method to do something different than the default built-in behavior, we can 'overload' the function by implementing new behavior under the __str__
method. However when we call the function, we still use str
without the dunders.
You can also do this with other built in operators and functions. For example, you can override the behavior of the ==
operator with __eq__
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