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 - Brianna #36

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

Branches - Brianna #36

wants to merge 5 commits into from

Conversation

brikemp
Copy link

@brikemp brikemp 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? An abstract data type is a date type that's implementation is independent of its behavior
Describe a Stack A stack is an ADT that follows the last in-first out rule
What are the 5 methods in Stack and what does each do? Initialize creates a new instance of the stack class. Push adds an element to the end of the stack. Pop removes the element at the end of the stack. Empty checks to see if there has been any data added to a stack. to_s returns an easily readable string of the data stored in the stack
Describe a Queue A queue is an ADT that follow the first 9n-first out rule
What are the 5 methods in Queue and what does each do? Initialize creates a new instance of the queue class. Enqueue adds an element to the end of a queue. Dequeue removes the element at the front of a queue. Size returns the number of items in a queue. Empty check to see whether there is any data in the queue. to_s returns an easily readable string of the data stored in the queue
What is the difference between implementing something and using something? Implementing something is required before something can be used and allows that instance to access methods specific to it.,

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, you hit the main learning goals here. There are some issues with the Queue class. Take a look at my comments and let me know any questions you have.

# Time Complexity: ?
# Space Complexity: ?
# Time Complexity: O(n) - n is chars in string
# Space Complexity: O(1/2n) --> O(n) - n is chars in string
def balanced(string)

Choose a reason for hiding this comment

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

👍

Comment on lines 27 to 29
# Time Complexity: ?
# Space Complexity: ?
def evaluate_postfix(postfix_expression)

Choose a reason for hiding this comment

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

👍

def enqueue(element)
raise NotImplementedError, "Not yet implemented"
if((@front == 0 && @back == @store.length - 1) || (@front == @back + 1))

Choose a reason for hiding this comment

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

It might be better to use `@front == (@back + 1) % @store.length

end


def dequeue

Choose a reason for hiding this comment

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

👍

raise ArgumentError
end

return @back - @front

Choose a reason for hiding this comment

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

This only works if @front < @back,

Suggested change
return @back - @front
return @back - @front if @front < @back
return @back + @store.length - @front

Comment on lines +51 to +55
if @front == -1 && @back == -1
return true
else
return false
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 == -1 && @back == -1
return true
else
return false
end
return @front == -1 && @back == -1

def to_s
return @store.to_s
return @store[@front...@back].to_s

Choose a reason for hiding this comment

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

Again this only works if front < back.

Comment on lines +63 to +72
# q = Queue.new
# q.enqueue(0)
# q.enqueue(1)
# q.enqueue(2)
# q.enqueue(3)
# p q
# p q.size
# p q.dequeue
# p q.size
# p q.front

Choose a reason for hiding this comment

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

This should probably be removed before submission

Suggested change
# q = Queue.new
# q.enqueue(0)
# q.enqueue(1)
# q.enqueue(2)
# q.enqueue(3)
# p q
# p q.size
# p q.dequeue
# p q.size
# p q.front

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