Skip to content

Conversation

@Blaine206
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 Structure
Describe a Stack LIFO : An ordered data structure (list/array), that hold elements, primary methods are to push (add) and pop (remove).
What are the 5 methods in Stack and what does each do? 1. pop : add 2. push : remove 3.peek : observes the top element 4. empty : checks if list is empty
Describe a Queue FIFO : list, can be an array, or circular buffer.
What are the 5 methods in Queue and what does each do? 1. enqueue : add 2.dequeue : remove 3.empty : empty? 4. size : the length of the list 5.front : value of item @ the front of the list (fifo)
What is the difference between implementing something and using something? Not sure I understand the question - implimenting is the how of something being executed - and using (to me implies) simply executing (using - something).

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.

You got it! Nice work Blaine, this works. Well done.

@@ -1,19 +1,23 @@
class Stack

Choose a reason for hiding this comment

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

👍

Comment on lines 55 to 58
def empty?
raise NotImplementedError, "Not yet implemented"
# return @front == -1
return @store.all?{ |e| e.nil? }
end

Choose a reason for hiding this comment

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

Why not instead check to see if front and back are both 0?

Copy link
Author

Choose a reason for hiding this comment

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

Honestly, didn't think of it. All I knew was I wanted to make sure the list was empty and I was getting errors because of nil so I googled for a fix. :-(

Comment on lines +14 to +16
elsif self.empty?
@front = 0
@back = 0

Choose a reason for hiding this comment

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

But if the Queue is empty, the back and front are already set to zero.


end

def dequeue

Choose a reason for hiding this comment

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

👍

return value
end

def front

Choose a reason for hiding this comment

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

👍

return @store.all?{ |e| e.nil? }
end

def to_s

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