Skip to content

Branches - Brianna#36

Open
brikemp wants to merge 5 commits into
Ada-C12:masterfrom
brikemp:master
Open

Branches - Brianna#36
brikemp wants to merge 5 commits into
Ada-C12:masterfrom
brikemp:master

Conversation

@brikemp

@brikemp brikemp commented Mar 3, 2020

Copy link
Copy Markdown

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?

@CheezItMan CheezItMan left a comment

Copy link
Copy Markdown

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.

Comment thread lib/problems.rb
# 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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍

Comment thread lib/problems.rb
Comment on lines 27 to 29
# Time Complexity: ?
# Space Complexity: ?
def evaluate_postfix(postfix_expression)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍

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

Copy link
Copy Markdown

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

Comment thread lib/queue.rb
end

def dequeue

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍

Comment thread lib/queue.rb
raise ArgumentError
end

return @back - @front

Copy link
Copy Markdown

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

Copy link
Copy Markdown

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

Comment thread lib/queue.rb
def to_s
return @store.to_s
return @store[@front...@back].to_s

Copy link
Copy Markdown

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 thread lib/queue.rb
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 No newline at end of file

Copy link
Copy Markdown

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