Skip to content

Conversation

@charlottea13
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 set of operations over unspecified data - not concrete data types
Describe a Stack Last In First Out ADT. no indexing. "a stack of plates"
What are the 5 methods in Stack and what does each do? push - adds to the stack, pop - removes from the stack, peek - gets value, empty - checks if stack is empty
Describe a Queue First In First Out - customers are served in the order in which they got in line.
What are the 5 methods in Queue and what does each do? enqueue - insertion to the rear, dequeue - remove from the front, front - returns value of front , size - returns length and empty - returns true/false
What is the difference between implementing something and using something? to implement is for the engineer who is developing the ADT. to use something is for the person who is interacting with the ADT but doesn't know the implementation details.

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.

You hit many of the learning goals here. However the Queue wasn't implemented with a circular buffer... which was the meat of the assignment.

Other than that things look good.

lib/problems.rb Outdated
Comment on lines 3 to 5
# Time Complexity: 0(n) where n is the length
# Space Complexity: 0(n)
def balanced(string)

Choose a reason for hiding this comment

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

Did you know that you can use a hash here where the keys are the open parens and the values are the matching close braces. That way you can quickly check to see if they match.

This does work however.

lib/queue.rb Outdated
raise NotImplementedError, "Not yet implemented"
def initialize(size=20)
@size = size
@store = Array.new()

Choose a reason for hiding this comment

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

You should probably start the array at the given size

Suggested change
@store = Array.new()
@store = Array.new(size)

@@ -1,28 +1,37 @@
class Queue

Choose a reason for hiding this comment

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

This works, but it's not what was asked. The assignment calls you to create a Queue using a circular buffer. So... yes it's a queue and passes the tests, but it wasn't implemented as requested.

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

Choose a reason for hiding this comment

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

👍

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.

Better, you have most of the circular buffer now. Well done.

Comment on lines +16 to +17
elsif @store.empty?
raise ArgumentError, "Full"

Choose a reason for hiding this comment

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

If the Queue is empty raise an argument error that it's full?

I think you want to check to see if it's full by doing if (@back + 1) % @store.length == @front

else
data = @store[@front]
@front = (@front + 1) % @size
if @store.empty?

Choose a reason for hiding this comment

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

You already checked to see if it's empty above with if @front == -1

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