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

Leaves - Samantha #30

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

Leaves - Samantha #30

wants to merge 4 commits into from

Conversation

iamsammysam
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? 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

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

end


def enqueue(element)

Choose a reason for hiding this comment

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

👍

end


def dequeue

Choose a reason for hiding this comment

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

👍

Comment on lines 43 to 45
def size
raise NotImplementedError, "Not yet implemented"
return @store[@front...@back].length
end

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?


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