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

Heather #14

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

Heather #14

wants to merge 7 commits into from

Conversation

piffer59
Copy link

@piffer59 piffer59 commented Sep 9, 2019

Stacks and Queues

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

Comprehension Questions

Question Answer
What is an ADT? Behavior is defined, but the implementation is not. You can implement it however you want.
Describe a Stack ADT, LIFO - new values are pushed or popped off the top of the stack
What are the 5 methods in Stack and what does each do? Initialize creates a new stack. Implementation is hidden. Push added a new element to the top of the stack. Pop removes the top element from the stack. Empty? returns a boolean saying whether the stack is empty or not. to_s prints the stack.
Describe a Queue ADT, FIFO - new elements are added to the back of the queue, elements are removed from the front of the queue
What are the 5 methods in Queue and what does each do? enqueue - adds a new element to the back of the queue, dequeue removes elements from the front of the queue, front - returns the element at the front of the queue, size - returns the length of the queue, empty? returns a boolean telling whether the queue is empty or not, to_s prints the queue
What is the difference between implementing something and using something? To use something you don't need to know how it's working under the hood, to implement something is to prescribe exactly how things are working under the hood

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.

Overall pretty good work. Take a look at my comments on the Queue, but otherwise outstanding work.

raise NotImplementedError, "Not implemented yet"
return true if string == ""

parens_hash = {

Choose a reason for hiding this comment

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

Good use of a hash!

elsif @front == (@rear + 1) % @store.length # queue is full
raise Error, "Q full"
else # queue not empty
@rear += 1

Choose a reason for hiding this comment

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

This needs to be @rear = (@rear + 1) % QUEUE_SIZE because the rear could wrap around the array.

raise NotImplementedError, "Not yet implemented"
if @front == -1 # queue is empty
@front = 0
@rear = 0

Choose a reason for hiding this comment

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

Starting front and rear at the same number could cause problems if someone tries to dequeue a few times.

end

def to_s
return @store.to_s
return @store[@front..@rear].to_s

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