Branches - Amal #44
Open
ashassan wants to merge 1 commit into
Open
Conversation
CheezItMan
reviewed
Mar 10, 2020
CheezItMan
left a comment
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
| def dequeue | ||
| raise NotImplementedError, "Not yet implemented" | ||
| if @front == -1 | ||
| raise ArgumenetError |
There was a problem hiding this comment.
Suggested change
| raise ArgumenetError | |
| raise ArgumentError, "Queue is Empty" |
Comment on lines
+23
to
+25
| elsif @front == @back | ||
| @front = -1 | ||
| @back = -1 |
There was a problem hiding this comment.
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.
After this line is where you should check to see if the queue is empty.
|
|
||
| def empty? | ||
| raise NotImplementedError, "Not yet implemented" | ||
| return true if @front = -1 && @back - 1 |
There was a problem hiding this comment.
Suggested change
| return true if @front = -1 && @back - 1 | |
| return @front = -1 && @back == - 1 |
|
|
||
| def to_s | ||
| return @store.to_s | ||
| return @store[@front + 1...@back].to_s |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacks and Queues
Thanks for doing some brain yoga. You are now submitting this assignment!
Comprehension Questions