Skip to content

Heather#14

Open
piffer59 wants to merge 7 commits intoAda-C11:masterfrom
piffer59:master
Open

Heather#14
piffer59 wants to merge 7 commits intoAda-C11:masterfrom
piffer59:master

Conversation

@piffer59
Copy link
Copy Markdown

@piffer59 piffer59 commented Sep 9, 2019

Stacks and Queues

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

Comprehension Questions

Question Answer
What is an ADT? Behavior is defined, but the implementation is not. You can implement it however you want.
Describe a Stack ADT, LIFO - new values are pushed or popped off the top of the stack
What are the 5 methods in Stack and what does each do? Initialize creates a new stack. Implementation is hidden. Push added a new element to the top of the stack. Pop removes the top element from the stack. Empty? returns a boolean saying whether the stack is empty or not. to_s prints the stack.
Describe a Queue ADT, FIFO - new elements are added to the back of the queue, elements are removed from the front of the queue
What are the 5 methods in Queue and what does each do? enqueue - adds a new element to the back of the queue, dequeue removes elements from the front of the queue, front - returns the element at the front of the queue, size - returns the length of the queue, empty? returns a boolean telling whether the queue is empty or not, to_s prints the queue
What is the difference between implementing something and using something? To use something you don't need to know how it's working under the hood, to implement something is to prescribe exactly how things are working under the hood

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.

Overall pretty good work. Take a look at my comments on the Queue, but otherwise outstanding work.

Comment thread lib/problems.rb
raise NotImplementedError, "Not implemented yet"
return true if string == ""

parens_hash = {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Good use of a hash!

Comment thread lib/queue.rb
elsif @front == (@rear + 1) % @store.length # queue is full
raise Error, "Q full"
else # queue not empty
@rear += 1
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 needs to be @rear = (@rear + 1) % QUEUE_SIZE because the rear could wrap around the array.

Comment thread lib/queue.rb
raise NotImplementedError, "Not yet implemented"
if @front == -1 # queue is empty
@front = 0
@rear = 0
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Starting front and rear at the same number could cause problems if someone tries to dequeue a few times.

Comment thread lib/queue.rb

def to_s
return @store.to_s
return @store[@front..@rear].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