Skip to content

Conversation

@shirley1chu
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? Abstract Data Type is agnostic about implementation details (such as whether an array or linked list is used to make a stack/queue), but is defined by the set of operations it can perform.
Describe a Stack ADT with LIFO structure. The last item added is the first to get removed
What are the 5 methods in Stack and what does each do? Push -> adds an element at top of the stack. Pop -> removes top element and returns the value. Is_empty -> boolean for whether stack is empty. Size -> returns length of stack. Peek -> returns top element value, but DOES NOT remove from stack.
Describe a Queue ADT with FIFO structure. First element added is first to get removed.
What are the 5 methods in Queue and what does each do?
  • enqueue: adds element to back of queue
  • dequeue: removes first element from q, returns element value
  • is_empty? : boolean whether q is empty
  • size: returns q length
  • front: returns value of first element, but doesn't remove it
What is the difference between implementing something and using something? Implement is creating something (writing a method) for use, and using is simply consuming it (calling a method).

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.

Nicely done. I like how you did the postfix exercise. You also did very well with the Queue and the circular buffer. Nice work!

require_relative './stack.rb'
require_relative "./stack.rb"

def balanced(string)

Choose a reason for hiding this comment

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

👍

return stack.empty?
end

def evaluate_postfix(postfix_expression)

Choose a reason for hiding this comment

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

Well done!

return @head == -1 ? nil : store[@head]
end

def size

Choose a reason for hiding this comment

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

Well done!

def to_s
return @store.to_s
clone_store = @store.clone
clone_store.delete(nil)

Choose a reason for hiding this comment

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

Clever

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