Skip to content

Conversation

@dtaylor73
Copy link

Stacks and Queues

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

Comprehension Questions

Question Answer
What is an ADT? It is a type of object which is described by the methods it has and how they perform. Implementation details are not included
Describe a Stack A Stack is a data structure which stores a list of data and only provides access in a Last-In-First-Out (LIFO) order.
What are the 5 methods in Stack and what does each do? Push (put data on the top of the stack), pop (delete data from the top of the stack), is_empty? (returns true if the stack is empty)
Describe a Queue A queue unlike a stack operates in a first-in-first out order. Like a line of people at a concert, the first element to enter the queue is the first element removed.
What are the 5 methods in Queue and what does each do? Enqueue (adds data to the back of the queue), dequeue (removes data from the front of the queue), front (returns the data at the front of the queue), size (returns the length of the queue), empty (returns true if the queue is empty)
What is the difference between implementing something and using something? A queue using an array, but the array is doing the 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.

Nice work, you hit the learning goals here. Well done. Take a look at my comments and let me know if you have questions.

raise NotImplementedError, "Not yet implemented"
@store = Array.new(100)
@front = @back = -1
@data = ''

Choose a reason for hiding this comment

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

Data?

# - 1 gets put into @back and the value of @back is put into @front
end

def enqueue(element)

Choose a reason for hiding this comment

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

👍




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

Choose a reason for hiding this comment

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

👍


def size
raise NotImplementedError, "Not yet implemented"
return @store.length

Choose a reason for hiding this comment

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

This only gives the size of the internal array size, not the number of elements in the Queue.

Comment on lines +51 to +53
return true if @front == @back

return false

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 == @back
return false
return @front == @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