Skip to content

Conversation

@codesrobertson
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; meaning a data type unlike a Linked List, where the name tells you how to implement the structure.
Describe a Stack A stack is an ADT that stores data in LIFO fashion.
What are the 5 methods in Stack and what does each do? Pop: removes element, Push: adds new element, To_S: makes a string of the elements, Empty?: lets you know if the stack is empty, Initialize: lets you create an instance of the stack class.
Describe a Queue A queue is an ADT that stores data in FIFO fashion.
What are the 5 methods in Queue and what does each do? Empty?: lets you know if the queue is empty, Initialize: lets you create an instance of the queue class, Enqueue: adds an element to the back of the queue, Dequeue: removes an element from the front of the queue, Front: shows where the queue starts, Size: shows how big the queue is.
What is the difference between implementing something and using something? Implementing implies that you, as the creator, know the exact implementation details. Using doesn't necessarily translate to implementation knowledge.

OPTIONAL JobSimulation

Question Answer
Did you include a sample run of your code as a comment? No

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 Alex, you hit the learning goals here. Well done.

Comment on lines +3 to 5
# Time Complexity: O(n)
# Space Complexity: O(n)
def balanced(string)

Choose a reason for hiding this comment

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

👍

}

string.each_char do |char|
if twosomes.values.include?(char)

Choose a reason for hiding this comment

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

Note about .include? is an O(n) operation and unnecessary in a hash.

Suggested change
if twosomes.values.include?(char)
if twosomes[char]

@back = -1
end

def enqueue(element)

Choose a reason for hiding this comment

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

👍

end
end

def dequeue

Choose a reason for hiding this comment

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

👍

Comment on lines 40 to +42
def front
raise NotImplementedError, "Not yet implemented"
return @queue[@front]
end

Choose a reason for hiding this comment

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

You should also check to see if the Queue is empty

Comment on lines +45 to 53
def get_queue_contents()
if @queue.empty?
return []
elsif @front > @back
return @queue[@front...@size] + @queue[0...@back]
else
return @queue[@front...@back]
end
end

Choose a reason for hiding this comment

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

I like this one!

@@ -1,22 +1,25 @@
class Stack

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