Skip to content

Conversation

@idago123
Copy link

@idago123 idago123 commented May 12, 2021

Stacks and Queues

Thanks for doing some brain yoga. You are now submitting this assignment!

Comprehension Questions

Question Answer
What is an ADT? A type of object which is described by the methods it has and how they perform.
Describe a Stack A data structure which stores a list of data and only provides access in a last in first out order.
What are the 5 methods in Stack and what does each do? push - adds an element to the end of the stackpop - removes and returns the item on the top of the stack.is_empty - checks if a stack is empty
Describe a Queue A data structure which stores a list of data and provides access in a first in first out order
What are the 5 methods in Queue and what does each do? enqueue - adds element to the back of the queue, dequeue - removes element from the front, is_empty - returns true if queue is empty, false if it isn't
What is the difference between implementing something and using 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.

Nice work Ida, I had a few comments on the Queue. Take a look at my comments and let me know what questions you have.

@@ -0,0 +1,15 @@
{

Choose a reason for hiding this comment

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

This could be added to .gitignore


end

def dequeue

Choose a reason for hiding this comment

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

👍

@@ -1,19 +1,23 @@
class Stack

Choose a reason for hiding this comment

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

👍

Comment on lines +38 to +42
elsif (@front == @size-1)
@front = 0
else
@front = @front + 1
end

Choose a reason for hiding this comment

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

This will let front wrap around without having to make the elif-else.

Suggested change
elsif (@front == @size-1)
@front = 0
else
@front = @front + 1
end
else
@front = (@front + 1) % @store.length
end

Comment on lines +20 to +21
@rear += 1
@queue[@rear] = element

Choose a reason for hiding this comment

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

This lets the rear wrap around

Suggested change
@rear += 1
@queue[@rear] = element
@rear = (@rear + 1) % @store.length
@queue[@rear] = element

idago123 and others added 2 commits May 25, 2021 15:52
Co-authored-by: Chris M <chris@adadevelopersacademy.org>
Co-authored-by: Chris M <chris@adadevelopersacademy.org>
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