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 - Julia Bouvier #31

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

Conversation

juliabouv
Copy link

@juliabouv juliabouv 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
Describe a Stack An ADT where elements are last in first out.
What are the 5 methods in Stack and what does each do? initialize sets up the internal structure as a linked list, push adds and element to the end of the stack, pop removes an element from the end of the stack, empty checks if the stack is empty, and to_s returns the stack as a string.
Describe a Queue An ADT where elements are first in first out.
What are the 5 methods in Queue and what does each do? enqueue adds a value to the back of the queue, dequeue removes the value from the front of the queue, front returns the front value, size returns the length of the queue, and empty checks if the queue is empty.
What is the difference between implementing something and using something? Implementing is creating something to be used, and using something is well, using that something.

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 not bad, some minor issues with your Queue class. Take a look at my comments and let me know any questions you have.

# @store = ...
raise NotImplementedError, "Not yet implemented"
@store = Array.new(30)
@front = @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.

👍


temp = @store[@front]
@store[@front] = nil
@front = (@front + 1) % @store.length

Choose a reason for hiding this comment

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

At this point you also need to check to see if @front == @back and if so, the queue is empty now and you need to reset them to -1.

Comment on lines +38 to +42
if @back.length > @front.length
return @back.length - @front.length
else
return @front.length - @back.length
end

Choose a reason for hiding this comment

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

back and front are numbers, how would they have lengths?

end

def empty?
raise NotImplementedError, "Not yet implemented"
@front == @back? true : false
end

def to_s

Choose a reason for hiding this comment

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

👍

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