-
Notifications
You must be signed in to change notification settings - Fork 41
Fire - Ida #29
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
base: master
Are you sure you want to change the base?
Fire - Ida #29
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 |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| { | ||
| // Use IntelliSense to learn about possible attributes. | ||
| // Hover to view descriptions of existing attributes. | ||
| // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
| "version": "0.2.0", | ||
| "configurations": [ | ||
| { | ||
| "name": "Debug Local File", | ||
| "type": "Ruby", | ||
| "request": "launch", | ||
| "program": "${workspaceRoot}/main.rb" | ||
| }, | ||
| null | ||
| ] | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,16 +1,47 @@ | ||||||||||||||||||
| class Queue | ||||||||||||||||||
|
|
||||||||||||||||||
| MAX_SIZE = 20 | ||||||||||||||||||
| def initialize | ||||||||||||||||||
| # @store = ... | ||||||||||||||||||
| raise NotImplementedError, "Not yet implemented" | ||||||||||||||||||
| @queue = [] | ||||||||||||||||||
| @size = 20 | ||||||||||||||||||
| @front = -1 | ||||||||||||||||||
| @rear = -1 | ||||||||||||||||||
|
|
||||||||||||||||||
| end | ||||||||||||||||||
|
|
||||||||||||||||||
| def enqueue(element) | ||||||||||||||||||
| raise NotImplementedError, "Not yet implemented" | ||||||||||||||||||
|
|
||||||||||||||||||
| if ((@front == 0 && @rear == @size - 1) || (@rear == @front && @front != -1) | ||||||||||||||||||
| raise "queue is full" | ||||||||||||||||||
| elsif (@front == -1) | ||||||||||||||||||
| @front = @rear = 0 | ||||||||||||||||||
| @queue[@rear] = element | ||||||||||||||||||
| else | ||||||||||||||||||
| @rear += 1 | ||||||||||||||||||
| @queue[@rear] = element | ||||||||||||||||||
|
Comment on lines
+20
to
+21
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. This lets the rear wrap around
Suggested change
|
||||||||||||||||||
| end | ||||||||||||||||||
|
|
||||||||||||||||||
| 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. 👍 |
||||||||||||||||||
| raise NotImplementedError, "Not yet implemented" | ||||||||||||||||||
| if (@front == -1) | ||||||||||||||||||
| raise "queue is empty" | ||||||||||||||||||
| end | ||||||||||||||||||
|
|
||||||||||||||||||
| result = @queue[@front] | ||||||||||||||||||
| @queue[@front] = nil | ||||||||||||||||||
|
|
||||||||||||||||||
| #if the queue is now empty | ||||||||||||||||||
| if (@front == @rear) | ||||||||||||||||||
| @front = -1 | ||||||||||||||||||
| @rear = -1 | ||||||||||||||||||
| elsif (@front == @size-1) | ||||||||||||||||||
| @front = 0 | ||||||||||||||||||
| else | ||||||||||||||||||
| @front = @front + 1 | ||||||||||||||||||
| 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. This will let front wrap around without having to make the elif-else.
Suggested change
|
||||||||||||||||||
|
|
||||||||||||||||||
| return result | ||||||||||||||||||
| end | ||||||||||||||||||
|
|
||||||||||||||||||
| def front | ||||||||||||||||||
|
|
@@ -22,10 +53,17 @@ def size | |||||||||||||||||
| end | ||||||||||||||||||
|
|
||||||||||||||||||
| def empty? | ||||||||||||||||||
| raise NotImplementedError, "Not yet implemented" | ||||||||||||||||||
| @front == -1 | ||||||||||||||||||
| end | ||||||||||||||||||
|
|
||||||||||||||||||
| def to_s | ||||||||||||||||||
| return @store.to_s | ||||||||||||||||||
| list = [] | ||||||||||||||||||
| index = @front | ||||||||||||||||||
| while index <= @rear | ||||||||||||||||||
| list.push(@queue[index]) | ||||||||||||||||||
| index = (index + 1) % @store.length | ||||||||||||||||||
| end | ||||||||||||||||||
|
|
||||||||||||||||||
| return list.to_s | ||||||||||||||||||
| end | ||||||||||||||||||
| end | ||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,23 @@ | ||
| 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 self.empty? | ||
|
|
||
| item = @store.remove_first | ||
|
|
||
| return item | ||
| end | ||
|
|
||
| def empty? | ||
| raise NotImplementedError, "Not yet implemented" | ||
| return @store.empty? | ||
| 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.
This could be added to
.gitignore