Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dani Sanchez - Paper #35

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

danisandiaz
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? Abstract Data Types describes a type where the implementation or methods are not known by the user
Describe a Stack A data structure used to save items that follows a Last in, First Out (LIFO) rule.
What are the 5 methods in Stack and what does each do? A stack will have a push methods( adds item to queue), a pop method (removes the last time added to the queue), and an is_empty method (returns boolean). A stack might also have a peek ( returns without removing item) and a size method (returns size of stack).
Describe a Queue A queue is a data structure that holds items and follows a First in, First out (FIFO) logic.
What are the 5 methods in Queue and what does each do? A Queue has a enqueue(add item to queue) method , a dequeue (removes item from queue) method, and an empty (returns boolean) method. It could also have a get_front (gets the first value in the queue) method and a get_size( finds the size of the queue) method.
What is the difference between implementing something and using something? Implementing something is writing the logic that will actually change/ organize/ store the data. Using a data structure, class, or method is calling that object on your data.

OPTIONAL JobSimulation

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

Copy link

@CheezItMan CheezItMan left a comment

Choose a reason for hiding this comment

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

Really nice work Dani, this works well. I left a little commentary on small things, but overall a solid submission.

Comment on lines +26 to +32
if self.size == self.buffer_size:
raise QueueFullException()


self.rear = (self.rear + 1) % self.buffer_size
self.store[self.rear] = element
self.size += 1

Choose a reason for hiding this comment

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

👍


return_value = self.store[self.front]
self.store[self.front] = None
self.front += 1

Choose a reason for hiding this comment

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

One correction

Suggested change
self.front += 1
self.front = (self.front + 1) % self.buffer_size

Comment on lines +80 to +89
if self.rear < self.front:
items_str = ", ".join(str(self.store[item]) for item in range(self.front, self.size - 1))
second_set_items = ", ".join(str(self.store[item]) for item in range(-1, self.rear + 1))
joined_items = "[" + items_str + ", " + second_set_items + "]"
return joined_items

else:
items_str = ", ".join(str(self.store[item]) for item in range(self.front, self.rear + 1))
joined_items = "[" + items_str + "]"
return joined_items

Choose a reason for hiding this comment

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

This is a little overcomplicated. You could instead start an index at self.front, and change it by current_index = (current_index + 1) % self.buffer_size adding each item to your output until you reach self.rear

@@ -12,7 +12,8 @@ def push(self, element):
""" Adds an element to the top of the Stack.

Choose a reason for hiding this comment

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

The stack looks good!

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