Skip to content

Conversation

@iris-lux
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 Type - a data type where only behavior is defined but not implementation
Describe a Stack A first-in, first-out data structure
What are the 5 methods in Stack and what does each do? pop: add to top of stack; push: remove and return top of stack; empty?: return if stack is empty; to_s: return string representation of stack
Describe a Queue A queue is a last-in, first-out data structure. Two common implementations are linked lists and circular buffers.
What are the 5 methods in Queue and what does each do? enqueue: add to end of queue; dequeue: remove and return front of queue; empty?: return if queue is empty; to_s: return string representation of stack
What is the difference between implementing something and using something? Implementation involves designing "behind-the-scenes" behaviors

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 Iris, you hit the learning goals here. Your queue methods are pretty slick and very compact. Well done.

@size += 1
if (@front == -1)
@front, @back = 0, 0
elsif(@back == (@store.length - 1) && @front != 0)

Choose a reason for hiding this comment

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

I don't think you need to check @front != 0 here because you did that on line 11.

@store[@back] = element
end

def dequeue

Choose a reason for hiding this comment

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

👍 , nicely done

return @front
end

def size

Choose a reason for hiding this comment

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

This should really return the number of items in the queue, not the size of the internal store.

@@ -1,19 +1,18 @@
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