Open
Conversation
CheezItMan
reviewed
Apr 7, 2021
CheezItMan
left a comment
There was a problem hiding this comment.
Nice work Kayla, these work. I left a few minor comments, but this was well done.
Comment on lines
+20
to
23
| Time Complexity: O(1) | ||
| Space Complexity: O(1) | ||
| */ | ||
| addFirst(value) { |
Comment on lines
+24
to
+28
| const addNode = new Node(value) // create Node object | ||
| addNode.next = this.#head // pointer 'next' is assigned to current head pointer | ||
| this.#head = addNode; //Head is now equal to new node | ||
| let current = this.#head //better name for head | ||
| return current |
There was a problem hiding this comment.
A little simpler
Suggested change
| const addNode = new Node(value) // create Node object | |
| addNode.next = this.#head // pointer 'next' is assigned to current head pointer | |
| this.#head = addNode; //Head is now equal to new node | |
| let current = this.#head //better name for head | |
| return current | |
| this.#head = new Node(value, this.#head); |
Comment on lines
+34
to
37
| Time Complexity: O(n) | ||
| Space Complexity: O(1) | ||
| */ | ||
| search(value) { |
Comment on lines
+56
to
59
| Time Complexity: O(n) | ||
| Space Complexity: O(1) | ||
| */ | ||
| findMax() { |
Comment on lines
+77
to
80
| Time Complexity: O(n) | ||
| Space Complexity: O(1) | ||
| */ | ||
| findMin() { |
Comment on lines
+132
to
135
| Time Complexity: O(n) * O(k) -- i don't know! You have to first traverse the linked list and THEN an array | ||
| Space Complexity: ??? | ||
| */ | ||
| visit() { |
There was a problem hiding this comment.
👍 , since you are traversing the list twice (once for the ll and the other time for the array) it's O(n + n) => O(n) in time complexity.
Since you are creating an array the space complexity is O(n).
Comment on lines
+136
to
+144
| let current = this.#head | ||
| if (current == null) return null; | ||
| let printJob = []; | ||
|
|
||
| while(current != null) { | ||
| printJob.push(current.value); | ||
| current = current.next; | ||
| } | ||
| console.log(printJob.join(' ')); //print array as string |
There was a problem hiding this comment.
Suggested change
| let current = this.#head | |
| if (current == null) return null; | |
| let printJob = []; | |
| while(current != null) { | |
| printJob.push(current.value); | |
| current = current.next; | |
| } | |
| console.log(printJob.join(' ')); //print array as string | |
| let current = this.#head | |
| if (current == null) return null; | |
| while (current != null) { | |
| console.log(current.value + ' '); | |
| current = current.next; | |
| } | |
Comment on lines
+148
to
151
| Time Complexity: O(n) | ||
| Space Complexity: O(1) | ||
| */ | ||
| delete(value) { |
Comment on lines
+176
to
179
| Time Complexity: O(n) | ||
| Space Complexity: O(1) | ||
| */ | ||
| reverse() { |
| @@ -142,7 +235,9 @@ class LinkedList { | |||
| Space Complexity: ? | |||
| */ | |||
| getFirst() { | |||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.