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 - Emily Ball #39

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

Branches - Emily Ball #39

wants to merge 4 commits into from

Conversation

eaball35
Copy link

@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

@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 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)

Choose a reason for hiding this comment

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

👍

@size = 20
@store = Array.new(@size)
@front = -1
@back = -1
end

def enqueue(element)

Choose a reason for hiding this comment

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

👍

end

@store[@back] = element
@back = (@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.

👍

end

def front
raise NotImplementedError, "Not yet implemented"
return nil if empty?
return @front

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 on lines +44 to +45
return @front - @back if @front > @back
return @back + (@store.length - @front)

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)

end

def empty?
raise NotImplementedError, "Not yet implemented"
@front == -1 && @back == -1
end

def to_s

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