-
Notifications
You must be signed in to change notification settings - Fork 49
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
base: master
Are you sure you want to change the base?
Branches - Amal #44
Conversation
There was a problem hiding this 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.
end | ||
if @front == @back | ||
raise ArgumenetError | ||
end |
There was a problem hiding this comment.
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.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
raise ArgumenetError | |
raise ArgumentError, "Queue is Empty" |
elsif @front == @back | ||
@front = -1 | ||
@back = -1 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Stacks and Queues
Thanks for doing some brain yoga. You are now submitting this assignment!
Comprehension Questions