Skip to content

Lety Palomo -Pine C-16 queue and stack project#57

Open
letypl12 wants to merge 1 commit intoAda-C16:masterfrom
letypl12:master
Open

Lety Palomo -Pine C-16 queue and stack project#57
letypl12 wants to merge 1 commit intoAda-C16:masterfrom
letypl12:master

Conversation

@letypl12
Copy link
Copy Markdown

@letypl12 letypl12 commented Jul 22, 2022

Stacks and Queues

Thanks for doing some brain yoga. You are now submitting this assignment!

Comprehension Questions

Question Answer
What is an ADT? Abstract data type is a representation of a data
Describe a Stack is a linear type of data structure that follows the LIFO (Last-In-First-Out) principle and allows insertion and deletion operations from one end of the stack data structure, that is top.
What are the 5 methods in Stack and what does each do? push, pop, is_empty, is_full
Describe a Queue One end is always used to insert data (enqueue) and the other is used to remove data (dequeue). Queue follows First-In-First-Out methodology, i.e., the data item stored first will be accessed first.
What are the 5 methods in Queue and what does each do? enqueue, dequeue, is_full, is empty, peek
What is the difference between implementing something and using something? Using is getting the benefits of something already created. Implementing is applying something to something more specific

OPTIONAL JobSimulation

Question Answer
Did you include a sample run of your code as a comment?

Copy link
Copy Markdown

@kyra-patton kyra-patton left a 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.

🟢

Comment thread stacks_queues/queue.py
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:
Copy link
Copy Markdown

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

Copy link
Copy Markdown
Author

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!

Comment thread stacks_queues/queue.py
@@ -23,39 +23,88 @@ def enqueue(self, element):
In the store are occupied
returns None
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread stacks_queues/queue.py
""" Removes and returns an element from the Queue
Raises a QueueEmptyException if
The Queue is empty.
"""
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread stacks_queues/queue.py
"""
pass

return self.store[self.front]
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread stacks_queues/queue.py
The Queue
"""
pass
return self.size
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread stacks_queues/queue.py
""" 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.
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread stacks_queues/stack.py
Returns None
"""
pass
return self.store.add_first(element)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread stacks_queues/stack.py
if self.store.length == 0:
raise StackEmptyException ("stack is empty")

return self.store.remove_first()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread stacks_queues/stack.py
Comment on lines +37 to +40
self.store.length = 0
if self.store.length == 0:
return True
return False
Copy link
Copy Markdown

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.

Suggested change
self.store.length = 0
if self.store.length == 0:
return True
return False
if self.store.length == 0:
return True
return False

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks!

Comment thread stacks_queues/stack.py
ending with the bottom of the Stack.
"""
pass
return self.store.__str__
Copy link
Copy Markdown

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__

Suggested change
return self.store.__str__
return str(self.store)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants