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 - Mariya #38

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Leaves - Mariya #38

wants to merge 1 commit into from

Conversation

M-Burr
Copy link

@M-Burr M-Burr commented Mar 3, 2020

Stacks and Queues

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

Comprehension Questions

Question Answer
What is an ADT? Abstract Data Type

| Describe a Stack | an ADT where elements that are last in, are first out |
| What are the 5 methods in Stack and what does each do? |

  1. Push: adds element to stack
  2. Pop: removes element from stack
  3. is_empty? : checks to see if stack is empty
  4. to_s: converts stack into a string
  5. initialize: creates a new stack |

| Describe a Queue | ADT where first element in is the first element out |

| What are the 5 methods in Queue and what does each do? |

  1. enqueue: add element to queue
  2. dequeue: removes element from queue
  3. is_empty? checks to see if queue is empty
  4. size: checks the size/length of queue
  5. initialize: creates new queue |

| What is the difference between implementing something and using something? | Implementing is like creating the code/function (e.g., a stack class), but using it requires calling on the implemented code to perform actions. Implementation is the creation of something, which needs to be done prior to using/utilizing that code. |

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.

Overall not bad, some minor issues with Queue. Otherwise it's pretty well done. Nice work

Comment on lines +17 to +22
front_array = @store.slice(0, @front)
back_array = @store.slice(@back, @store.length - 1)
@store = front_array + Array.new(10) + back_array
@front = (@front + 10) % @store.length
end

Choose a reason for hiding this comment

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

This assumes that front is less than back

Comment on lines +28 to +31
removed = @store[@front]
@store[@front] = nil
@front = (@front + 1) % @store.length
return removed

Choose a reason for hiding this comment

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

You should also check if the queue is now empty.

Comment on lines +43 to +47
if @front == @back
return true
else
return false
end

Choose a reason for hiding this comment

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

Suggested change
if @front == @back
return true
else
return false
end
return @front == @back

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