Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kristy, Branches #29

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Kristy, Branches #29

wants to merge 3 commits into from

Conversation

kristyh32
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
Describe a Stack A stack is a LIFO abstract data structure
What are the 5 methods in Stack and what does each do? Initialize makes a new stack with an empty linked list, push adds a new item onto the stack, pop takes the top item off the list, empty tells you whether the stack has anything in it, and to_s prints out what's int the stack
Describe a Queue A queue is a FIFO abstract data structure
What are the 5 methods in Queue and what does each do? enqueue adds to the back of the queue, dequeue takes the item from the front of the queue, size tells you how many items are in the queue, and front tells you what the item at the front of the queue is without taking it off
What is the difference between implementing something and using something? If you implement something you're putting the pieces of it in place/setting it up. Using it is using it.

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.

Some issues with your Queue class. Take a look at my comments and let me know if you have questions. Other than that this works.

@@ -3,7 +3,25 @@
# 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.

👍

Comment on lines +15 to +17
if @front == @back
#decide
end

Choose a reason for hiding this comment

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

This part works better as an elsif to raise an error if the queue is full. You're not doing anything here.

end

def dequeue

Choose a reason for hiding this comment

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

You also need to check if the queue is empty before and after you dequeue an element.

Comment on lines 38 to 40
def size
raise NotImplementedError, "Not yet implemented"
return @store.compact.length
end

Choose a reason for hiding this comment

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

This works, but it's quite expensive O(n) for both space and time and you lose some of the benefits of the circular buffer.

def empty?
raise NotImplementedError, "Not yet implemented"
@store.compact.empty? ? true : false

Choose a reason for hiding this comment

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

Why the conditional? Why not just return @store.compact.empty?

Oh and like the previous method, this becomes very expensive.

def to_s
return @store.to_s
return @store.compact.to_s

Choose a reason for hiding this comment

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

This mostly works, but if back < front, the order of materials in the queue won't be maintained.

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