Skip to content

Amy P#21

Open
aphunk wants to merge 6 commits intoAda-C11:c11-updatesfrom
aphunk:master
Open

Amy P#21
aphunk wants to merge 6 commits intoAda-C11:c11-updatesfrom
aphunk:master

Conversation

@aphunk
Copy link

@aphunk aphunk commented Sep 11, 2019

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 Structures are objects that are described by their methods and behaviors, and not by their implementation.
Describe a Stack A stack is a data structure for which its elements can only be accessed in last in, first out order.
What are the 5 methods in Stack and what does each do? 1. Initialize - creates a new stack; 2. Push - adds to the top of the stack; 3. Pop - removes from the top; 4. Empty - determines whether the stack is empty or not; 5. to_s - presents the data in the stack as a string
Describe a Queue A queue is a data structure in which operates in a first in, first out order.
What are the 5 methods in Queue and what does each do? 1. Initialize - creates a new queue; 2. Enqueue - adds to the back of the queue; 3. Dequeue - removes and returns the element from the front of the queue; 4. is_empty - determines whether the queue is empty or not; 5. to_s - presents the data in the queue as a string
What is the difference between implementing something and using something? To implement something is involves applying the behaviors and patterns for that thing; to use something involves the utilization of those behaviors and patterns.

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.

Overall a lot of promise there with some issues. You did pretty well with the circular buffer and almost had the matching parentheses problem.

Take a look at my comments and let me know what questions you have.

end

list.each do |char|
if bracket_buds.values.include?(char)

Choose a reason for hiding this comment

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

Should that be values or keys?

require_relative './stack.rb'

def balanced(string)
bracket_buds = {

Choose a reason for hiding this comment

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

love the name

end
end

def dequeue

Choose a reason for hiding this comment

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

Really good!

end

def size
return @store[@front..@rear].length

Choose a reason for hiding this comment

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

This is a little expensive way to do this. Maybe instead just do some math.

def to_s
elements_in_queue = []
i = @front
while i < @rear

Choose a reason for hiding this comment

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

What if the rear has wrapped around?

Maybe instead you could do until i == @rear

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