Skip to content

Conversation

@krismosk
Copy link

@krismosk krismosk commented Mar 5, 2020

Stacks and Queues

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

Comprehension Questions

Question Answer
What is an ADT? A data type that is defined by its behavior
Describe a Stack A stack is a container of objects that are inserted and removed according to the last-in first-out (LIFO) principle
What are the 5 methods in Stack and what does each do? Size returns length of queue. Unshift adds one item to the queue. Push adds an element to end of queue. Pop removes last item from queue and Close closes the queue.
Describe a Queue A queue is FIFO; like a line at the DMV
What is the difference between implementing something and using something? Implementing something is defining how something is used verses actually using it.

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.

Stack is working fine, but you have some issues with Queue. Take a look at my comments and let me know what questions you have.

Comment on lines 3 to 5
# Time Complexity: ?
# Space Complexity: ?
def balanced(string)

Choose a reason for hiding this comment

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

The method works, time and space complexity?

Comment on lines +11 to +14
end

if @front == @back
end

Choose a reason for hiding this comment

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

Suggested change
end
if @front == @back
end
elsif @front == @back
# Raise an error if the Queue is full
end

def dequeue
raise NotImplementedError, "Not yet implemented"
if @front == @back
return "queue is empty"

Choose a reason for hiding this comment

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

It would be better to raise an error in this circumstance.

data = @store[@front]
@store[@front] = nil

if @front == @back

Choose a reason for hiding this comment

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

I think you need to advance front before comparing it to back.

Comment on lines +48 to +50
if @front == @back
return true
end

Choose a reason for hiding this comment

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

Suggested change
if @front == @back
return true
end
return @front == @back

end

def to_s
@store.delete(nil)

Choose a reason for hiding this comment

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

This will shrink the internal array. It's both an expensive operation and it will also not maintain the order of elements in the Queue.

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