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

Branches - Amal #44

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Branches - Amal #44

wants to merge 1 commit into from

Conversation

ashassan
Copy link

@ashassan ashassan commented Mar 4, 2020

Stacks and Queues

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

Comprehension Questions

Question Answer
What is an ADT? ADT is a type of object which is described by the methods it has and how they perform
Describe a Stack stacks store a list of data but only provides access in last-in-first-out order.
What are the 5 methods in Stack and what does each do? initialize creates a new instance of stack. The pop method puts an item at the top of the stack. The pop method removes the top item of the stack and returns it. The method is_true returns a boolean depending on if it is empty.
Describe a Queue stores data but only provides access in first-in-first-out order
What is the difference between implementing something and using something? you need to implement something before it can be used
When is a circular buffer advantageous over a dynamic array or LinkedList?

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.

Your Stack class works, but Queue has some serious issues. Take a look at my comments and let me know what questions you have.

Comment on lines +12 to +15
end
if @front == @back
raise ArgumenetError
end

Choose a reason for hiding this comment

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

I suggest making this an elsif otherwise front and back will have an extra space between them due to the fact that the 1st if sets back at 1.

Suggested change
end
if @front == @back
raise ArgumenetError
end
@back = 0
elsif @front == @back
raise ArgumentError, "Queue is full"
end

end

def dequeue
raise NotImplementedError, "Not yet implemented"
if @front == -1
raise ArgumenetError

Choose a reason for hiding this comment

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

Suggested change
raise ArgumenetError
raise ArgumentError, "Queue is Empty"

Comment on lines +23 to +25
elsif @front == @back
@front = -1
@back = -1

Choose a reason for hiding this comment

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

The queue won't be empty until you remove an element and advance @front

else
first = @store[@front]
@store[@front] = nil
@front = (@front + 1) % @store.length

Choose a reason for hiding this comment

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

After this line is where you should check to see if the queue is empty.

@@ -22,10 +41,10 @@ def size
end

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

Choose a reason for hiding this comment

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

Suggested change
return true if @front = -1 && @back - 1
return @front = -1 && @back == - 1

end

def to_s
return @store.to_s
return @store[@front + 1...@back].to_s

Choose a reason for hiding this comment

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

This doesn't work, and assumes that @front < @back.

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