-
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 - Julia Bouvier #31
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,57 @@ | ||
class Queue | ||
|
||
def initialize | ||
# @store = ... | ||
raise NotImplementedError, "Not yet implemented" | ||
@store = Array.new(30) | ||
@front = @back = -1 | ||
end | ||
|
||
def enqueue(element) | ||
raise NotImplementedError, "Not yet implemented" | ||
if @front == -1 && @back == -1 | ||
@front = 0 | ||
@back = 0 | ||
end | ||
|
||
if ((@back + 1) % @store.length) == @front | ||
raise ArgumentError.new "Queue is full" | ||
end | ||
|
||
@store[@back] = element | ||
@back = (@back + 1) % @store.length | ||
end | ||
|
||
def dequeue | ||
raise NotImplementedError, "Not yet implemented" | ||
if @front == @back | ||
raise ArgumentError.new "Queue is full" | ||
end | ||
|
||
temp = @store[@front] | ||
@store[@front] = nil | ||
@front = (@front + 1) % @store.length | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At this point you also need to check to see if |
||
return temp | ||
end | ||
|
||
def front | ||
raise NotImplementedError, "Not yet implemented" | ||
return @store[@front] | ||
end | ||
|
||
def size | ||
raise NotImplementedError, "Not yet implemented" | ||
if @back.length > @front.length | ||
return @back.length - @front.length | ||
else | ||
return @front.length - @back.length | ||
end | ||
Comment on lines
+38
to
+42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. back and front are numbers, how would they have lengths? |
||
end | ||
|
||
def empty? | ||
raise NotImplementedError, "Not yet implemented" | ||
@front == @back? true : false | ||
end | ||
|
||
def to_s | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
if @front < @back | ||
@store = @store[@front...@back] | ||
elsif @front != @back | ||
@store = @store[@back..-1] + @store[@front...@back] | ||
end | ||
return @store.to_s | ||
end | ||
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.
👍