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

Janice H. #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Janice H. #32

wants to merge 1 commit into from

Conversation

jaitch
Copy link

@jaitch jaitch commented Mar 3, 2020

Chris--Sorry, I didn't have much time this week and didn't quite finish this assignment. I will try to do more in the next few days and push any changes, but I thought it would be better to first submit what I have. Thanks.

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, where the implementation is hidden from the user
Describe a Stack like a stack of dishes, only top is accessible. LIFO
What are the 5 methods in Stack and what does each do? initialize starts a new stack using a linked list (in my implementation), push adds an element to the back, pop takes an element off the back, empty return a boolean indicating if the stack is empty or not, to_s converts the stack
Describe a Queue a line, here represented by an array. FIFO
What are the 5 methods in Queue and what does each do? initialize creates a new queue, enqueue adds a new element to the back, dequeue takes an element from the front, front returns the front, size gives the size of the queue, empty returns a boolean value stating if the queue is empty or not
What is the difference between implementing something and using something? when you implement something you make it possible to use it.

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, but you have some issues and unfinished methods in Queue. I also suggest you not use puts unless the method's purpose is output. Instead raise an error or return a meaningful value.

Take a look at my comments and let me know any questions.

Comment on lines +17 to +18
@store[@back-1] = element
@back = (@back + 1) % @store.length # to get back to index 0

Choose a reason for hiding this comment

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

you're having to do @back-1 because you have set @back to 1 in the first if in this method and you wrote two separate ifs. Converting if @front == @back into an elsif would make this a bit more straightforward.

def dequeue
raise NotImplementedError, "Not yet implemented"
if @front == -1 && @back == -1
puts 'queue is empty, sorry!'

Choose a reason for hiding this comment

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

I would raise an error here instead of puts.

return
end
value = @store[@front]
@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.

You also need to check if the queue is now empty here.

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

Choose a reason for hiding this comment

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

Suggested change
return true if @front == -1 && @back == -1
return @front == -1 && @back == -1

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.

3 participants