Skip to content

Conversation

@kashenafi
Copy link

@kashenafi kashenafi commented Jun 26, 2021

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 an object that is defined by its methods--the actual implementation is hidden to the public user.
Describe a Stack An ABT that stores data in a LIFO order
What are the 5 methods in Stack and what does each do? pop: removes and returns the item on the top of the stack; push: pushes an item to the top of the stack; peek: returns the item at the top of the stack (but does not remove); is_empty: returns true if the stack is empty, false otherwise; size: returns the number of items on the stack
Describe a Queue An ABT that stores data in a FIFO order
What are the 5 methods in Queue and what does each do? enqueue: puts an item to the back of the queue; dequeue: removes and returns the item at the front of the queue; front: returns the item at the front of the queue (but does not remove); is_empty: returns true if the queue is empty, false otherwise; size: returns the number of items in the queue
What is the difference between implementing something and using something? Implementing something is when you build something and use it strategic to how you want things done--using it is just using something that is made.

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 Kal, well done. You hit the learning goals here.

Comment on lines +16 to +20
elsif @back == (MAX_SIZE - 1) && @front != 0
@back = 0
else
@back += 1
end

Choose a reason for hiding this comment

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

This could also be written as:

Suggested change
elsif @back == (MAX_SIZE - 1) && @front != 0
@back = 0
else
@back += 1
end
else
@back = (@back + 1) % MAX_SIZE
end


if @front == @back # queue is now empty
@front = @back = -1
elsif @front + 1 == MAX_SIZE

Choose a reason for hiding this comment

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

Just a note that this could be updated similar to what I mentioned in enqueue.

return @front == @back
end

def 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