Skip to content

Kayla - 🌊 (SORRY I'M LATE!!!)#3

Open
Kaylaj89 wants to merge 2 commits intoAda-C14:masterfrom
Kaylaj89:master
Open

Kayla - 🌊 (SORRY I'M LATE!!!)#3
Kaylaj89 wants to merge 2 commits intoAda-C14:masterfrom
Kaylaj89:master

Conversation

@Kaylaj89
Copy link

No description provided.

Copy link

@CheezItMan CheezItMan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines +56 to 59
Time Complexity: O(n)
Space Complexity: O(1)
*/
findMax() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines +77 to 80
Time Complexity: O(n)
Space Complexity: O(1)
*/
findMin() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

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() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 , 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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment on lines +176 to 179
Time Complexity: O(n)
Space Complexity: O(1)
*/
reverse() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@@ -142,7 +235,9 @@ class LinkedList {
Space Complexity: ?
*/
getFirst() {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants