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

Erica #18

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

Erica #18

wants to merge 2 commits into from

Conversation

norrise120
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? ADT - Abstract Data Type, a datatype where the mechanics are not public, but users are able to add or delete.
Describe a Stack A stack is a list were items are added on top of each other, so first item in the list is the last item out of the list.
What are the 5 methods in Stack and what does each do? Initialize creates the stack, push adds elements to the stack at the end, pop takes away elements from the stack starting at the end, empty? returns a boolean depending on whether the stack is empty or not, and to_s formats the stack into a readable string.
Describe a Queue A queue is a list where elements are added behind each other, so first item in the list is the first item out of the list.
What are the 5 methods in Queue and what does each do? Enqueue adds to the rear of the queue. Dequeue removes from the front of the queue. Empty? determines if the queue has elements or not. to_s formats it so that the elements are returned as a string, and initialize creates the queue.
What is the difference between implementing something and using something? Implementing is creating a method (or class, etc) while using is calling a method (or making an instance of a class, etc).

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.

Not bad, you hit most of the learning goals. In particular see my notes on your Stack implementation. Let me know if you have questions.

else
dequeued = @store[@front]
@store[@front] = nil
@front = (@front + 1) % QUEUE_SIZE

Choose a reason for hiding this comment

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

You should also check to see if the queue is now empty.

end

def empty?
raise NotImplementedError, "Not yet implemented"
queue = @store.compact

Choose a reason for hiding this comment

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

This is a pretty expensive way to see if the queue is empty.

Why not just return @front == -1?

end

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

Choose a reason for hiding this comment

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

This is a bit expensive. You could also calculate the size based on the locations of front and rear.

end

def push(element)
raise NotImplementedError, "Not yet implemented"
if @front == -1

Choose a reason for hiding this comment

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

You don't really need a circular buffer for a Stack as you only add or remove on one end (the top). Instead I'd asked you to use a Linked List. So this is a little weird.

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