Skip to content

Conversation

@alexandria7
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 abstract data type is a data type that is characterized not by what it is made of but rather the operations it performs and rules it follows. It describes the implementation of whatever data type you use.
Describe a Stack An abstract data type that is characterized by its push and pop methods and its following of "last in, first out", i.e. when you remove or "pop" an element from a stack, what is removed is the last thing that was added or "pushed" to it.
What are the 5 methods in Stack and what does each do? pop => removes the item from the top of the stack i.e. the last item added; push => takes a value and adds it to the top of the stack; peek => looks at whatever the value is at the top of the stack and returns it; empty? => returns true if the stack is empty, false if it is not; initialize => creates access to whatever data type you will be utilizing for the stack
Describe a Queue An abstract data type that is characterized by its enqueue and dequeue methods and its following of "first in first out", i.e. when you dequeue an element from the queue it begins with whatever was added to it first.
What are the 5 methods in Queue and what does each do? enqueue => takes an element and adds it to the queue; dequeue => removes an element from the queue, starting with the item that was added first; empty? => returns true if the stack is empty, false if it is not; initialize => creates access to whatever data type you will be utilizing for the queue; front/peek => returns the element at the beginning/front of the queue
What is the difference between implementing something and using something? Implementing something means taking something to infer or define functionality, while using something implies just producing a result.

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 nice work, you hit the learning goals here. Take a look at my comments and let me know if you have any questions.

def evaluate_postfix(postfix_expression)
raise NotImplementedError, "Not implemented yet"
end
numbers = {

Choose a reason for hiding this comment

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

Nice use of a hash!

def initialize
# @store = ...
raise NotImplementedError, "Not yet implemented"
@store = [Array.new(QUEUE_SIZE)]

Choose a reason for hiding this comment

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

An array of arrays?

Copy link
Author

@alexandria7 alexandria7 Sep 10, 2019

Choose a reason for hiding this comment

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

WHOOPS! totally a mistake


def size
raise NotImplementedError, "Not yet implemented"
filled_spots = @store.select { |val| val != nil }

Choose a reason for hiding this comment

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

This is a little bit less efficient than if you started at the front and counted through until you found the rear, or better yet calculated the size.


def to_s
return @store.to_s
adjusted_store = @store.select { |val| val != nil }

Choose a reason for hiding this comment

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

If the rear wraps around the array, the output here wouldn't be quite right.

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