Skip to content

Conversation

shainabeth
Copy link

Stacks and Queues

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

Comprehension Questions

Question Answer
What is an ADT? a type that only says what methods should exist, but doesn't actually implement them.
Describe a Stack a type that only allows you to add/remove items to the front.
What are the 5 methods in Stack and what does each do? push: add an item to the front, pop: remove an item from the front, peek: look at the first item, empty: check if there are values in the stack, size: how many items are in the stack
Describe a Queue a data structure where you always put items on one side and remove items from the other side. Like a queue in real life.
What are the 5 methods in Queue and what does each do? push: add an item to the front, pop: remove an item from the back, peek: look at the last item, empty: check if there are values in the queue, size: how many items are in the queue
What is the difference between implementing something and using something? implementing something is telling the program how to do something, using it is running that code.

OPTIONAL JobSimulation

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

Copy link

@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! I left a few comments making some recommendations for how you might refactor your code, but it looks like you understand queues with a circular buffer and stacks with linked lists. Let me know what questions you have.

For the comprehension questions, I would note that when adding/removing items from a Stack you do not necessarily have to append/remove from the front of an array - rather you must always append and remove from the same side. For implementing vs using, you are mostly correct. However, I want to clarify that using the code could also be using a library or calling a function someone else wrote; you don't need to necessarily run a program with that code.

🟢

returns None
"""
pass
if self.size == INITIAL_QUEUE_SIZE:

Choose a reason for hiding this comment

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

I would suggest comparing to buffer_size instead of your constant. That way, if you were ever to expand or adapt this class to have a buffer size that could increase or decrease, you code would still work without needing to change all references to INITIAL_QUEUE_SIZE to the new buffer size.

Suggested change
if self.size == INITIAL_QUEUE_SIZE:
if self.size == self.buffer_size:

""" Adds an element to the Queue
Raises a QueueFullException if all elements
In the store are occupied
returns None

Choose a reason for hiding this comment

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

✨ However, see my comment regarding your use of INITIAL_QUEUE_SIZE below ⬇️

def dequeue(self):
""" Removes and returns an element from the Queue
Raises a QueueEmptyException if
The Queue is empty.

Choose a reason for hiding this comment

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


return to_ret

def front(self):

Choose a reason for hiding this comment

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

return self.store[self.front]


def size(self):

Choose a reason for hiding this comment

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

""" 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.

Choose a reason for hiding this comment

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

Returns None
"""
pass
self.store.add_first(element)

Choose a reason for hiding this comment

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

Comment on lines +24 to +26
v = self.store.get_first()
self.store.remove_first()
return v

Choose a reason for hiding this comment

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

If you read the docstrings of the LinkedList class, you'll see that remove_first returns the value of the node it removes.

Suggested change
v = self.store.get_first()
self.store.remove_first()
return v
return self.store.remove_first()

self.store.remove_first()
return v

def empty(self):

Choose a reason for hiding this comment

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

✨ Alternatively, you could take advantage of the LinkedList class' empty method

pass
return self.store.get_first() == None

def __str__(self):

Choose a reason for hiding this comment

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

✨ Alternatively, you could take advantage of the LinkedList class' str method

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