Skip to content

Leaves - Samantha#30

Open
iamsammysam wants to merge 4 commits into
Ada-C12:masterfrom
iamsammysam:master
Open

Leaves - Samantha#30
iamsammysam wants to merge 4 commits into
Ada-C12:masterfrom
iamsammysam:master

Conversation

@iamsammysam
Copy link
Copy Markdown

Stacks and Queues

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

Comprehension Questions

Question Answer
What is an ADT? An Abstract Data Type, 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(item) = puts an item into the stack at the top, pop = removes and returns the item on the top of the stack, is_empty = returns true if the stack is empty and false otherwise, peek = returns but does not remove the item on top of the stack and size = returns the number of items on the stack.
Describe a Queue A queue unlike a stack operates in a first-in-first out order, 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(item) = puts an item into the back of the queue, dequeue = removes and returns the item at the front of the queue, is_empty = returns true if the queue is empty and false otherwise, front = returns the item at the front, but leaves the queue unchanged and size = returns the number of items on the queue.
What is the difference between implementing something and using something? When you implement methods they only depend on themselves to work but when you use some tool, for example data structures like arrays or linked lists as part of those methods they depend on the previous implementation of something (those data structures) to work.

OPTIONAL JobSimulation

Question Answer
Did you include a sample run of your code as a comment?

Copy link
Copy Markdown

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

Some minor issues with your Queue class, but overall well done. I like how you executed the enqueue and dequeue methods. Nice!

Comment thread lib/queue.rb
end

def enqueue(element)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍

Comment thread lib/queue.rb
end

def dequeue
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍

Comment thread lib/queue.rb
Comment on lines 43 to 45
def size
raise NotImplementedError, "Not yet implemented"
return @store[@front...@back].length
end
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This only works if @front < @back. What about if @back has wrapped around the buffer?

Comment thread lib/queue.rb
return @front == -1
end
def to_s
Copy link
Copy Markdown

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