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

Water - Beatrice #25

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

Water - Beatrice #25

wants to merge 2 commits into from

Conversation

Beatress
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 data type that hides its internal working through encapsulation. It is often based off of primitive datatypes
Describe a Stack A stock is like a pile of books that can only be manipulated from the top. It operates on a last in first out model
What are the 5 methods in Stack and what does each do? Push puts an item on the top of the stack. Pop takes an item and returns it off the top of the stack. Then there is a method to check if the stack is empty
Describe a Queue A queue is like a line of people. Items are added to the back and leave from the front. This means that it operates on a first in first out model
What are the 5 methods in Queue and what does each do? A queue has methods to enqueue, putting an element at the end, dequeue, taking an element from the beginning of the queue, check if it is empty, peek at the first element, and return the length
What is the difference between implementing something and using something? When you implement something you have to be concerned with all of the details, but when you use something you just have to worry about how it is used

OPTIONAL JobSimulation

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

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.

Nice work Beatrice, you hit the main learning goals here. Well done.

Comment on lines +12 to +14
if @front == (@back + 1) % @size
self.expand
end

Choose a reason for hiding this comment

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

This defeats the circular nature of the list, so that you can work with a fixed size, but it does let you resize the buffer.

@size = 10
@store = Array.new(@size)
@front = 0
@back = 0
end

def enqueue(element)

Choose a reason for hiding this comment

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

👍

end

@store[@back] = element
@back = (@back + 1) % @size
end

def dequeue

Choose a reason for hiding this comment

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

👍

end

def front
raise NotImplementedError, "Not yet implemented"
return @store[@front]
end

def size

Choose a reason for hiding this comment

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

Size should be the number of elements in the queue not the size of the underlying buffer.

end

def to_s
return @store.to_s
return @store[@front..(@back-1)].to_s

Choose a reason for hiding this comment

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

What if @back < @front

@@ -1,19 +1,19 @@
class Stack

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