Skip to content

Conversation

haset-19
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? is a type of object which is described by the methods it has and how they perform. Implementation details are not included
Describe a Stack Is a data structure that stores lists of data but those data can be accessed through last in-first out
What are the 5 methods in Stack and what does each do? size, to return the total elements in a stack, is_empty to check if the stack is empty, pop to remove and return the element on top of the stack, push to insert element on the top, peek, to return top element but not doesn't remove
Describe a Queue is an abstract data structure to store a list of elements like stack but allows access only in first come first out
What are the 5 methods in Queue and what does each do? enqueue to add element at the end, dequeue to remove element from the front, is_empty, to check if the queue is empty, size to calculate the total elements and return
What is the difference between implementing something and using something? Implementing something the way the implementer prefers and abstracting the details, the data structures used etc, and the user doesn't have to know the details.

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 couple of suggestions. Great job on the comprehension questions. Let me know what questions you have.

🟢

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

Choose a reason for hiding this comment

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

The Queue is empty.
"""
pass
if self.empty():

Choose a reason for hiding this comment

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

is empty. Does not remove anything.
"""
pass
return self.store[self.front]

Choose a reason for hiding this comment

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

The Queue
"""
pass
return self.size

Choose a reason for hiding this comment

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

And False otherwise.
"""
pass
return self.front == self.rear

Choose a reason for hiding this comment

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

👀 This will check if the queue is empty, but it could also mean the queue

Comment on lines +86 to +88
while (start_index % INITIAL_QUEUE_SIZE) < INITIAL_QUEUE_SIZE and len(queue_list) < self.size:
if self.store[start_index % INITIAL_QUEUE_SIZE] is not None:
queue_list.append(self.store[start_index % 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 recommend using self.buffer_size instead of the constants for style reasons. It will also allow us to expand our queue functionality in the future, say if we wanted to increase buffer_size instead of just raising an error.

Suggested change
while (start_index % INITIAL_QUEUE_SIZE) < INITIAL_QUEUE_SIZE and len(queue_list) < self.size:
if self.store[start_index % INITIAL_QUEUE_SIZE] is not None:
queue_list.append(self.store[start_index % INITIAL_QUEUE_SIZE])
while (start_index % self.buffer_size) < self.buffer_size and len(queue_list) < self.size:
if self.store[start_index % self.buffer_size] is not None:
queue_list.append(self.store[start_index % self.buffer_size])

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

"""
pass

return self.store.remove_first()

Choose a reason for hiding this comment

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

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.

pass
return self.store.empty()

def __str__(self):

Choose a reason for hiding this comment

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

✨ This works, but you might also consider taking advantage of LinkedList's 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