Skip to content

Conversation

@ktvoort123
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 ADT is an abstract data type, which means that it's a type of object which is described by the methods it has and how they perform, although there are no specific details on how to implement it.
Describe a Stack A stack is a data structure which stores a list of data which can be accessed using a Last-In-First-Out system.
What are the 5 methods in Stack and what does each do? The five methods in a stack are push, pop, is_empty, peek, and size. Push puts an item into the top of the stack. Pop removes the item on the top of the stack and returns it. Is_empty determines whether or not the stack is empty. Peek returns the first item on the stack. Size returns the number of items in the stack.
Describe a Queue A queue is a data structure that stores data in a First-In-First-Out order.
What are the 5 methods in Queue and what does each do? The five methods in a queue are enqueue, deueue, is_empty, front, and size. Enqueue puts an item into the back of the queue. Dequeue removes the item at the front of the queue and returns it. Is_empty determines whether or not the queue is empty. Front returns the first item on the queue. Size returns the number of items in the queue.
What is the difference between implementing something and using something? Implementing something means that you have to decide the specifics of how to make it work. Using something is when it already exists.

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.

Katie, well done. You hit the main learning goals here. Nice work. Take a look at my comments and let me know what questions you have.

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

Choose a reason for hiding this comment

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

👍 Space and time complexity?

I like the use of the hash here!

@store[@front] = element
return element
elsif @front == (@rear + 1) % @size # queue full
puts("the qeue is full yo")

Choose a reason for hiding this comment

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

😮

return element
elsif @front == (@rear + 1) % @size # queue full
puts("the qeue is full yo")
raise NotImplementedError

Choose a reason for hiding this comment

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

I suggest you raise a different error here.

@rear = -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.

👍

qeue_front = self.front
if @front != @rear
@store[@front] = nil
@front += 1

Choose a reason for hiding this comment

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

Suggested change
@front += 1
@front = (@front + 1) % @store.length

Comment on lines 36 to 38
def front
raise NotImplementedError, "Not yet implemented"
return @store[@front]
end

Choose a reason for hiding this comment

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

You should probably check to see if the Queue is empty

return @store[@front]
end

def size

Choose a reason for hiding this comment

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

Why not use the positions of front and rear to calculate the size of the Queue.

return count
end

def empty?

Choose a reason for hiding this comment

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

Again I suggest that you use front and rear to tell if the queue is empty.

@@ -1,19 +1,19 @@
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