-
Notifications
You must be signed in to change notification settings - Fork 41
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
Fire - Noor #23
base: master
Are you sure you want to change the base?
Fire - Noor #23
Changes from 3 commits
d651453
8bcf829
244dade
e2fdea3
89f09c7
1b2c3d0
b904c45
2abaa95
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,61 @@ | ||
class Queue | ||
Array_Length = 20 | ||
|
||
def initialize | ||
# @store = ... | ||
raise NotImplementedError, "Not yet implemented" | ||
@store = Array.new(Array_Length) | ||
@front = @back = 0 | ||
end | ||
|
||
def enqueue(element) | ||
raise NotImplementedError, "Not yet implemented" | ||
if @front.nil? | ||
@front = @back = 0 | ||
elsif (@front - @back == 1) || (@back - @front == Array_Length - 1) | ||
raise ArgumentError, 'Queue is full' | ||
end | ||
|
||
@store[@back] = element | ||
@back = (@back + 1) % Array_Length | ||
end | ||
|
||
def dequeue | ||
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. 👍 , very compact, nicely done! |
||
raise NotImplementedError, "Not yet implemented" | ||
if @front == @back || @front.nil? | ||
raise ArgumentError, 'Queue is empty' | ||
end | ||
|
||
temp = @store[@front] | ||
@front = (@front + 1) % Array_Length | ||
return temp | ||
end | ||
|
||
def front | ||
raise NotImplementedError, "Not yet implemented" | ||
return @store[@front] | ||
end | ||
|
||
def size | ||
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. 👍 |
||
raise NotImplementedError, "Not yet implemented" | ||
return 0 if @front == -1 | ||
if @front < @back | ||
@back - @front + 1 | ||
else | ||
Array_Length - @front + @back | ||
end | ||
end | ||
|
||
def empty? | ||
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. 👍 |
||
raise NotImplementedError, "Not yet implemented" | ||
if @front.nil? || @front == @back | ||
return true | ||
else | ||
return false | ||
end | ||
end | ||
|
||
def to_s | ||
return @store.to_s | ||
results = [] | ||
if @back >= @front | ||
results = @store[@front...@back] | ||
else | ||
results = @store[@front...Array_Length] + (@store[0...@back]) | ||
end | ||
return results.to_s | ||
end | ||
|
||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,20 @@ | ||
class Stack | ||
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. 👍 |
||
def initialize | ||
# @store = ... | ||
raise NotImplementedError, "Not yet implemented" | ||
@store = LinkedList.new() | ||
end | ||
|
||
def push(element) | ||
raise NotImplementedError, "Not yet implemented" | ||
@store.add_first(element) | ||
end | ||
|
||
def pop | ||
raise NotImplementedError, "Not yet implemented" | ||
return nil if @store.empty? | ||
@store.remove_first | ||
end | ||
|
||
def empty? | ||
raise NotImplementedError, "Not yet implemented" | ||
return true if @store.empty? | ||
return false | ||
end | ||
|
||
def 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.
👍