Skip to content

Conversation

@anakp07
Copy link

@anakp07 anakp07 commented May 3, 2021

Stacks and Queues

Thanks for doing some brain yoga. You are now submitting this assignment!

Comprehension Questions

Question Answer
What is an ADT? An Abstract Data Type is an object which is described by the methods it has and how they perform. It has a public interface but implementation details are private.
Describe a Stack A Stack is a data structure which stores a list of data and only provides access in a Last-In-First-Out (LIFO) order.
What are the 5 methods in Stack and what does each do? The initialize method which starts the stack. push(item) - This method puts an item into the stack at the top. pop - This method removes and returns the item on the top of the stack. is_empty - This method returns true if the stack is empty and false otherwise. To_s - Turns implementation into readable format
Describe a Queue A queue is like a stack but it operates in a first-in-first out order. Like a line of people at a concert, the first element to enter the queue is the first element removed.
What are the 5 methods in Queue and what does each do? Initialize which creates array of specified size. enqueue(item) - This method puts an item into the back of the queue. dequeue - This method removes and returns the item at the front of the queue. is_empty - This method returns true if the queue is empty and false otherwise.
What is the difference between implementing something and using something? Implementing is the details in how you choose to make something work. Using something is how you expect the the method to perform.

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.

Ana, you hit the main learning goals here. I had a few comments and let me know if you have questions on them.

def enqueue(element)
raise NotImplementedError, "Not yet implemented"

if (@front == 0 && @rear == @size - 1) ||

Choose a reason for hiding this comment

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

Why the -1 in @front - 1 and @size - 1?

@store[@rear] = element
end

def dequeue

Choose a reason for hiding this comment

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

👍

return removed_data
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[@front]
end

def size

Choose a reason for hiding this comment

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

⚠️ This gives ths size of the store and not the size of the stuff in the queue.


def empty?
raise NotImplementedError, "Not yet implemented"
return @front == -1 || @front == @back

Choose a reason for hiding this comment

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

Suggested change
return @front == -1 || @front == @back
return @front == -1

If you add 1 element with your algorithm, front will equal back (and you still have 1 thing in the queue).


end

def to_s

Choose a reason for hiding this comment

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

Could you handle this using:

i = (i + 1) % @SiZe

in a simpler manner.

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