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

Queues - Cara Comfort - stacks-queues #37

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

Conversation

cecomfort
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 ADT is an abstract data type. It specifies the rules we must follow when interacting with data. An ADT can restrict the possible values, possible operations on data of this type, and the behavior of these operations.
Describe a Stack A stack is an ordered list where all insertions and removals are made only from the top. It follows the rules of LIFO.
What are the 5 methods in Stack and what does each do? 1. push(e) -> adds an element to the top of the stack, 2. pop -> removes the element at the top of the stack, 3. empty? -> returns T or F depending on whether or not the stack contains any elements, 4. top -> returns the top element without removing it, 5. size -> returns how many elements are contained in the stack
Describe a Queue A queue is an ordered list where all iterations are done at the back and all removals are done at the front. It follows the rules of FIFO.
What are the 5 methods in Queue and what does each do? 1. enqueue(e) -> adds an element to the back of the queue, 2. dequeue -> removes the element at the front of the queue, 3. empty? -> returns T or F depending on whether or not the queue contains any elements, 4. front -> returns the front element without removing it, 5. size -> returns how many elements are contained in the queue
What is the difference between implementing something and using something? When we implement something, we are defining that thing, while when we use it, we are using something that has been previously defined.

OPTIONAL JobSimulation

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

end

def pop
raise ArgumentError.new("Cannot pop an empty stack") if @store.empty? #OR self.empty?

Choose a reason for hiding this comment

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

good!

# seekers_left = job_seekers - jobs_available
((jobs_available + 1)..job_seekers).each do |worker|
@waiting.enqueue("Worker ##{worker}")
end

Choose a reason for hiding this comment

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

yes! nice!

@waiting.enqueue("Worker ##{worker}")
end

@roll

Choose a reason for hiding this comment

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

Remove this as it's not needed here

end

def cycle
roll

Choose a reason for hiding this comment

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

Just put the rolling method body here - it's only one line, so no need for a new method for it


# fire workers specified by the roll, removing them from the hired list
# and adding them to the waiting list
(1..@roll).each do

Choose a reason for hiding this comment

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

I think this would read cleaner if you did @roll.times instead

@sudocrystal
Copy link

Stacks and Queues

What We're Looking For

Feature Feedback
Implementation of Stack looks complete yes
Implementation of Queue looks complete yes

OPTIONAL JobSimulation

Extension Feedback
Does the code solve the problem to specification? yes
Is the code easy to follow? yes
Does the output look good? yes
Were provided variables and methods used appropriately and not altered in name or definition? yes
Were any new variables and/or methods made private to the class? yes

This looks really good! I put in to add any new methods as private, which is maybe why you made that roll method. I don't actually think that you need any new methods other than the two I requested (initialize and cycle) so I'll probably take that question out in the future.

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.

None yet

2 participants