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

Angela #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Angela #7

wants to merge 1 commit into from

Conversation

AngelaOh
Copy link

@AngelaOh AngelaOh commented Sep 8, 2019

Stacks and Queues

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

Comprehension Questions

Question Answer
What is an ADT? An ADT is an abstract data class. It does not specify internal implementation.
Describe a Stack A Stack is a data structure that operates in a last in first out order.
What are the 5 methods in Stack and what does each do? Push adds an element to the end of a data structure. Pop removes from the end. Empty? checks if the stack has any elements inside. Peak returns a value but does not remove like pop does. To_s returns the stack in a readable format.
Describe a Queue A Queue is a data structure that operates in a first in first out order.
What are the 5 methods in Queue and what does each do? EnQ adds an element to the rear. DeQ removes an element from the front. Front returns the value at the front. Size returns the number of elements inside the queue. Empty checks if the queue contains any elements.
What is the difference between implementing something and using something? Implementing implies the class knows the inner workings of the action while using something does not necessarily know whats going on under the hood.

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 don't have the postfix problem done, but overall not bad. You do have some issues with the circular buffer. Take a look at my comments and let me know if you have questions.

@@ -1,7 +1,25 @@
require_relative './stack.rb'

def balanced(string)
raise NotImplementedError, "Not implemented yet"
return false if string.length % 2 != 0

Choose a reason for hiding this comment

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

👍

def dequeue # remove from front
removed = @store[@front]
@store[@front] = nil
self.size == 0 ? @front = -1 : @front += 1

Choose a reason for hiding this comment

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

What about the front wrapping around the array. Instead of @front +=1 you should have @front = (@front + 1) % QUEUE_SIZE

end

def size
raise NotImplementedError, "Not yet implemented"
size = 0
@store.each do |val|

Choose a reason for hiding this comment

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

This is less efficient than starting at @front and progressing through the array until you reach @rear, or keeping an instance variable for size.

return @store.to_s
def to_string
formatted_array = []
@store.each do |x|

Choose a reason for hiding this comment

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

This assumes @front < @rear, that's not always going to be true.

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