Skip to content

Branches - Emily Ball#39

Open
eaball35 wants to merge 4 commits intoAda-C12:masterfrom
eaball35:master
Open

Branches - Emily Ball#39
eaball35 wants to merge 4 commits intoAda-C12:masterfrom
eaball35:master

Conversation

@eaball35
Copy link
Copy Markdown

@eaball35 eaball35 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 - a type of object which is described by the methods it has and how they perform. Public interface is provided but implementation details are private.
Describe a Stack Data structure, Last in - First out, Like a stack of books
What are the 5 methods in Stack and what does each do? 1. Initialize : creates a new LinkedList, 2. Push: Adds element to top of stack, 3. Pop: Takes last in element off of stack, 4. Empty? - Checks if stack has nothing in it, 5. To_s - Turns implementation into readable format
Describe a Queue Data structure, First in - First out, Like a line in a store
What are the 5 methods in Queue and what does each do? 1. Initialize : Creates array of specified size, 2. Dequeue: Remove element from queue 3. Enqueue: Adds element into queue 4. Front: Returns the front pointer in circular buffer implementation 5. To_s: Returns implementation in readable format
What is the difference between implementing something and using something? Implementing is the details in which you choose to make something work. For example using an array or LinkedList. Using something is how you expect the abstraction to perform. For example, when you use the Queue class you expect it to work like a data structure that stores in elements first in, first out and has certain common methods despite implementation.

OPTIONAL JobSimulation

Question Answer
Did you include a sample run of your code as a comment? ?

Copy link
Copy Markdown

@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 have some minor issues with Queue, but otherwise this is very well done. Nice work! You hit all the major learning goals here. Well done.

Comment thread lib/problems.rb
Comment on lines +3 to 5
# Time Complexity: O(n) where n is characters in string
# Space Complexity: O(n) where n is characters 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/queue.rb
@back = -1
end

def enqueue(element)
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
@back = (@back + 1) % @store.length
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
def front
raise NotImplementedError, "Not yet implemented"
return nil if empty?
return @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.

Suggested change
return @front
return @stores[@front]

Comment thread lib/queue.rb
Comment on lines +44 to +45
return @front - @back if @front > @back
return @back + (@store.length - @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.

I think you have this reversed here.

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

Comment thread lib/queue.rb
@front == -1 && @back == -1
end

def 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.

👍 This works, but you could do it with just a single loop like while i != @back

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