Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Branches - Erika #33

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

Branches - Erika #33

wants to merge 9 commits into from

Conversation

emaust
Copy link

@emaust emaust commented Mar 3, 2020

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
Describe a Stack LIFO
What are the 5 methods in Stack and what does each do? initialize instantiates a new stack object, push - adds element to top of stack, pop - removes and returns element at top of stack, is_empty checks if stack is empty, to_s prints the stack
Describe a Queue FIFO
What are the 5 methods in Queue and what does each do? enqueue adds value to back of queue, dequeue removes the value at front of queue, front returns the value at the front of the queue, size returns the number of values within the queue, and empty checks if there are any current values stored
What is the difference between implementing something and using something? Implementing involves the creation for the intent to use and use is utilizing something already created

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 with Queue and your balanced method here. Take a look at my comments and let me know what questions you have.

lib/problems.rb Outdated
Comment on lines 8 to 10
openers = ["{", "[", "("]
closers = ["}", "]", ")"]

Choose a reason for hiding this comment

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

I suggest using a hash here instead of arrays where the key is an open brace and the value is the close.

lib/problems.rb Outdated
Comment on lines 20 to 37
until count == length || stack_size > string.length/2
char = string[count]
# if the value is in openers, add to stack
if openers.include?(char)
stack.push(char)
stack_size += 1
# if the value is in closers, pop from stack
else
if closers.include?(char)
stack.pop
stack_size -= 1
# if it's in neither, return false
else
return false
end
end
count += 1
end

Choose a reason for hiding this comment

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

You're on the right track here. I suggest, like I did above using a hash to match up open and close braces.

lib/queue.rb Outdated
def enqueue(element)
raise NotImplementedError, "Not yet implemented"
end
def enqueue(element)

Choose a reason for hiding this comment

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

What about when the queue is empty, and what about when it's full?

lib/queue.rb Outdated
end

def size
raise NotImplementedError, "Not yet implemented"
end

def empty?
raise NotImplementedError, "Not yet implemented"
return true if @front == -1 && @rear == -1

Choose a reason for hiding this comment

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

You're assuming the queue is empty if front and rear are -1, but your initialize method sets them to 0.

Also when you dequeue above if the queue is now empty, you would then need to set them to -1.

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

Comment on lines 5 to 7
# 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.

👍 , Time & space complexity?

end

def dequeue
raise NotImplementedError, "Not yet implemented"
def dequeue

Choose a reason for hiding this comment

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

👍

end

def front
raise NotImplementedError, "Not yet implemented"
return @store[@front]
end

def size

Choose a reason for hiding this comment

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

👍

Comment on lines 58 to 60
def empty?
raise NotImplementedError, "Not yet implemented"
return @front == @rear
end

Choose a reason for hiding this comment

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

I think this should actually be:

return @front == -1 && @rear == -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