-
Notifications
You must be signed in to change notification settings - Fork 44
Time - Yesenia #39
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?
Time - Yesenia #39
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(20) | ||
| @max_size = 20 | ||
| @front = -1 | ||
| @rear = -1 | ||
| end | ||
|
|
||
| def enqueue(element) | ||
|
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 | ||
| @front = 0 | ||
| @rear = 1 | ||
| @store[@front] = element | ||
|
|
||
| elsif @front == @rear | ||
| raise ArgumentError, "Queue is at max capacity" | ||
|
|
||
| else | ||
| @store[@rear] = element | ||
| @rear = (@rear + 1) % @max_size | ||
| 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" | ||
| end | ||
| if @front == -1 | ||
| raise ArgumentError, "Queue is empty" | ||
| else | ||
| element = @store[@front] | ||
| @front = (@front + 1) % @max_size | ||
|
|
||
| def front | ||
| raise NotImplementedError, "Not yet implemented" | ||
| if @front == @rear | ||
| @front = @rear = -1 | ||
| end | ||
|
|
||
| return element | ||
| end | ||
| end | ||
|
|
||
| def size | ||
| raise NotImplementedError, "Not yet implemented" | ||
| def front | ||
| return @store[@front] | ||
| 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" | ||
| return @front == @rear | ||
| end | ||
|
|
||
| def to_s | ||
| return @store.to_s | ||
| queue = [] | ||
| current = @front | ||
| while current != @rear | ||
| queue << @store[current] | ||
| current = (current + 1) % @max_size | ||
| end | ||
| return queue.to_s | ||
| end | ||
| end | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,18 @@ | ||
| 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 # using provided Linked List class | ||
| end | ||
|
|
||
| def push(element) | ||
| raise NotImplementedError, "Not yet implemented" | ||
| @store.add_last(element) | ||
| end | ||
|
|
||
| def pop | ||
| raise NotImplementedError, "Not yet implemented" | ||
| return @store.remove_last | ||
| 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.
👍 Nice work!