Skip to content

Spruce: Kaitlyn#51

Open
kaitlyngore wants to merge 2 commits intoAda-C16:masterfrom
kaitlyngore:master
Open

Spruce: Kaitlyn#51
kaitlyngore wants to merge 2 commits intoAda-C16:masterfrom
kaitlyngore:master

Conversation

@kaitlyngore
Copy link
Copy Markdown

@kaitlyngore kaitlyngore commented Jul 18, 2022

Stacks and Queues

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

Comprehension Questions

Question Answer
What is an ADT? An object that is described by the methods it performs, not its implementation details. So the user of the class may not know exactly how the methods are done.
Describe a Stack A stack works in a last-in-first out order. So things are added to and pulled off the top.
What are the 5 methods in Stack and what does each do? init - creates the stack, with a linked list to store future elements; push - adds an element to the top; pop - removes the top element; empty - returns whether the stack is empty; str - prints the elements so they look like a list
Describe a Queue A queue is the opposite of a stack. It works with items in a last-in-first-out order
What are the 5 methods in Queue and what does each do? init - creates the queue and sets the max size; enqueue - adds an element to the end of the queue; dequeue - removes an element from the end of the queue; front - returns the front element; size - returns the size; empty - returns whether the queue is empty; str - prints the queue elements so they look like a list
What is the difference between implementing something and using something? Implementing is literally creating how that thing works. Using it is calling the method or function, etc. To use something, you don't need to know how it works, you just need to know it does what you want it to.

OPTIONAL JobSimulation

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

@kaitlyngore kaitlyngore changed the title Spruce Spruce: Kaitlyn Jul 18, 2022
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.

✨🌸 Nice work, Kaitlyn. I left a few suggestions and comments, but overall very solid implementations for both classes.

For the comprehension questions, I believe this may have been a typo, but note that a queue is actually first in first out (FIFO) not last in first out (LIFO).

Let me know what questions you have.

🟢

Comment thread stacks_queues/queue.py
""" Adds an element to the Queue
Raises a QueueFullException if all elements
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
The Queue is empty.
"""
pass
if self.front == -1:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since you never check after dequeueing an element, whether the queue becomes empty and thus you should move the front and rear pointers back to -1, this conditional may not always work. Try using the empty method you implement below instead.

Suggested change
if self.front == -1:
if self.empty():

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
And False otherwise.
"""
pass
return (self.size == 0)
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.size == 0)

def __str__(self):
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.head == None:
raise StackEmptyException("The 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.

Per the specification, this should return None

Suggested change
return self.store.remove_first()
self.store.remove_first()

Comment thread stacks_queues/stack.py
"""
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.

Per the specification, the function should return None

Suggested change
return self.store.add_first(element)
self.store.add_first(element)

Comment thread stacks_queues/stack.py
Comment on lines +34 to +37
if self.store.head == None:
return True
else:
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.

✨ This does work. You could also consider taking advantage of LinkedList's empty method

Comment thread stacks_queues/stack.py
else:
return False

def __str__(self):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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