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

Elle #13

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

Elle #13

wants to merge 5 commits into from

Conversation

dev-elle-up
Copy link

@dev-elle-up dev-elle-up 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? ADT stands for Abstract Data Type. An ADT is described by the methods it has, which are made available through a public interface while the implementation details are kept hidden. It is a concept that can be implemented using primitive data types, such as arrays, linked lists, hashes, and binary trees.
Describe a Stack A stack is an abstract data type that acts like a pile of books. Only one end of a stack can be accessed (the "top") for both adding things to and removing things from the stack. It is a LIFO procedure.
What are the 5 methods in Stack and what does each do? The 5 methods are initialize, push, pop, empty? and to_s. Initialize makes a new instance of Stack, which calls LinkedList.new, resulting in a new instance of the LinkedList class. The other methods simply call a corresponding method in the LinkedList class! This is a great example of an Abstract Data Type, where the details of the methods are kept behind the scenes.
Describe a Queue A queue is a concept - an ADT - that acts just like a line of people waiting their turns for a service (grocery store checkout, for example). Both ends of the queue are accessible but only for particular actions. That is, you can add to the rear of the queue and remove from the front of the queue. It operates in FIFO order.
What are the 5 methods in Queue and what does each do? Initialize creates a new instance of the Queue class, which is an array with a fixed size. Enqueue adds an element to the rear of the queue and then updates the @rear pointer. Dequeue removes an item from the front of the queue and updates the @front pointer. Empty? returns true if the queue is empty and false if not. To_s builds a string that represents all of the items in the queue (array) from the @front pointer to the @rear pointer.
What is the difference between implementing something and using something? To implement a something (a class or a method) is to build it; to write its methods, or to write the code for the function. Something is used when another class or method references or calls it via its public interface.

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.

Really good work here! You did a great job especially with the circular buffer in the Queue. Let me know if you have any questions with my comments.

@@ -1,9 +1,68 @@
require_relative './stack.rb'

def balanced(string)
raise NotImplementedError, "Not implemented yet"

Choose a reason for hiding this comment

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

Nice!

else
@store[@rear] = element
@rear = (@rear + 1) % QUEUE_SIZE
end
end

def dequeue

Choose a reason for hiding this comment

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

Great work here!

lib/queue.rb Outdated
i = @front + 1
until i == @rear
array_as_string = array_as_string + ", #{@store[i]}"
i += 1

Choose a reason for hiding this comment

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

Since the array could wrap around, you should do i = (i + 1) % QUEUE_SIZE

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