-
Notifications
You must be signed in to change notification settings - Fork 4
Aimee 👾 - Fire 🔥 #4
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?
Changes from all commits
a2c6e81
25f5e04
0eb5c82
a43a161
5b39a2f
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,15 +1,31 @@ | ||
| class Queue { | ||
| static maxLenth = 20; | ||
|
|
||
| constructor() { | ||
| // this.store = ... | ||
| throw new Error("This method has not been implemented!"); | ||
| this.store = new Array(); | ||
| this.head = 0; | ||
| this.tail = 0; | ||
| } | ||
|
|
||
| enqueue(element) { | ||
| throw new Error("This method has not been implemented!"); | ||
| enqueue(value) { | ||
|
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. 👍 |
||
| let len = this.store.length; | ||
| if (this.head === this.tail && !this.isEmpty()) { | ||
| throw new Error("Queue is Full!") | ||
| } | ||
| this.store[len] = value; | ||
| this.tail = (this.tail + 1) % Queue.maxLenth; | ||
| } | ||
|
|
||
| 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. You should also check to see if the |
||
| throw new Error("This method has not been implemented!"); | ||
| let len = this.store.length; | ||
| if (len === 0) { | ||
| return; | ||
| } | ||
|
|
||
| const value = this.store[this.head]; | ||
| this.store[this.head] = null; | ||
| this.head = (this.head + 1) % Queue.maxLenth; | ||
| return value; | ||
| } | ||
|
|
||
| front() { | ||
|
|
@@ -21,7 +37,7 @@ class Queue { | |
| } | ||
|
|
||
| isEmpty() { | ||
| throw new Error("This method has not been implemented!"); | ||
| return !this.store[this.head] || this.store[this.head] === undefined; | ||
| } | ||
|
|
||
| toString() { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,27 @@ | ||
| const LinkedList = require('./linked-list') | ||
|
|
||
| class Stack { | ||
| constructor() { | ||
| // this.store = ... | ||
| throw new Error("This method has not been implemented!"); | ||
| this.store = new LinkedList; | ||
| } | ||
|
|
||
| push() { | ||
| throw new Error("This method has not been implemented!"); | ||
| push(value) { | ||
|
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.store.addLast(value); | ||
| } | ||
|
|
||
| pop() { | ||
|
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. 👍 |
||
| throw new Error("This method has not been implemented!"); | ||
| const lastValue = this.store.getLast() | ||
| this.store.delete(lastValue); | ||
| return lastValue; | ||
| } | ||
|
|
||
| isEmpty() { | ||
|
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. 👍 |
||
| throw new Error("This method has not been implemented!"); | ||
| const len = this.store.length() | ||
| if (len > 0) { | ||
| return false; | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| toString() { | ||
|
|
||
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.
👍 I'm pretty sure the
popmethod has O(1) time complexity leading your solution to O(n) time complexity overall.