Skip to content

Conversation

Anagabsoares
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? An Abstract Data Type, is a type of object which is described by the methods it has and how they perform.
Describe a Stack A Stack is a data structure which stores a list of data and only provides access in a Last-In-First-Out (LIFO) order
What are the 5 methods in Stack and what does each do? push() -. add element ,pop() - remove element , is_empty() - check if stack is empty, display() -> display elements
Describe a Queue Queue is the data structure that is similar to the queue in the real world. A queue is a data structure in which whatever comes first will go out first, and it follows the FIFO (First-In-First-Out) policy.
What are the 5 methods in Queue and what does each do? queue() _> add element to the queue dequeu() - remove element front() -> get first element is_empty() -> check if queue is empty size()-> return queue length
What is the difference between implementing something and using something? Implementing -> development from scratch/ using - make use of something that already exists

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, Ana. Please check your implementation of front for the Queue class. I also left some minor style suggestions, but overall good work. Let me know what questions you have.

🟢

"""
pass
if self.size == self.buffer_size:
raise QueueFullException('This will break it')

Choose a reason for hiding this comment

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

Small suggestion: When raising an exception, it's helpful to give a description of why the code is breaking

Suggested change
raise QueueFullException('This will break it')
raise QueueFullException('Queue full')

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.

# find element in the store
# First in first out
if self.size == 0:
raise QueueEmptyException('This will break it')

Choose a reason for hiding this comment

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

Same thing as above with the Exception here ⬆️

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

pass

if self.store[self.front]:
return self.store[0]

Choose a reason for hiding this comment

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

⚠️ With a circular queue, the front of the queue may not always be at index 0. That's why we have a front pointer that shifts as elements are dequeued.

The current tests don't cover front which is why you may not have caught this.

Suggested change
return self.store[0]
return self.store[self.front]

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

pass

self.store.add_last(element)
return element

Choose a reason for hiding this comment

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

Per the specification, this function should return None

Suggested change
return element

if not self.store:
raise StackEmptyException("List is empty")

return self.store.remove_last()

Choose a reason for hiding this comment

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

Again, per the function specification, this method should return None

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

And False otherwise
"""
pass
return self.store.empty()

Choose a reason for hiding this comment

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

ending with the bottom of the Stack.
"""
pass
values = []

Choose a reason for hiding this comment

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

✨ Yes, this works! You could also take advantage of the str method in the LinkedList class

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