Skip to content

Conversation

@Faiza1987
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?
Describe a Stack
What are the 5 methods in Stack and what does each do?
Describe a Queue
What are the 5 methods in Queue and what does each do?
What is the difference between implementing something and using something?

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.

Some issues here with the circular buffer, but overall this is pretty good. Take a look at my comments and let me know where you have questions.

"{" => "}",
}

stack = Stack.new

Choose a reason for hiding this comment

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

Nicely done

if @front == -1 # Q is empty
return

elsif @front == @rear # There's only 1 element

Choose a reason for hiding this comment

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

When front and rear are equal, the Queue is not empty, it's full.

When they're equal after removing an element, then the queue is empty.

array = []
@store.each_with_index do |element, i|
next if i < @front
break if element.nil?

Choose a reason for hiding this comment

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

What if you've removed 1 element from the front of the queue. Then @store[0] will be nil, and you'll exit the loop early here.

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