Skip to content

Conversation

@lebaongoc
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? It stands for Abstract Data Type: a type of data structure described by a set of operations it can perform
Describe a Stack A Stack is an abstract data type that stores data in a Last-in-first-out order ( like a stack of dishes
What are the 5 methods in Stack and what does each do? push(item): this method adds an item to the end of the stack, pop: this method removes the last item from the stack, length: returns the length of a stack, empty?: checks if the stack has any items, to_s: returns the stack in string
Describe a Queue it is a ADT that stores data in a FIFO order ( like a people line up at the bank)
What are the 5 methods in Queue and what does each do? enqueue(element): add an element to the queue, dequeue: remove the first element of the queue, empty: check if the queue is empty, size: return the number of elements in the queue, to_s: print the queue to string
What is the difference between implementing something and using something? with implementing something, the implementer needs to know how it works. When you use something, you just need to know what it does

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.

Nice work! You hit all the learning goals here. Well done.

Comment on lines +9 to +12
if (stack.get_last() == "{" && char == "}") ||
(stack.get_last() == "[" && char == "]") ||
(stack.get_last() == "(" && char == ")")
stack.pop()

Choose a reason for hiding this comment

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

This can be done a lot more elegantly with a hash.


def empty?
raise NotImplementedError, "Not yet implemented"
if @size == 0

Choose a reason for hiding this comment

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

Using a size variable like this will work, you could also do a bit of math with front and rear.

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