Complete the code to declare a class property for the node's value.
class Node { value: [1]; next: Node | null; constructor(value: number) { this.value = value; this.next = null; } }
The node's value is a number, so the property type should be number.
Complete the code to initialize the next pointer to null in the constructor.
class Node { value: number; next: Node | null; constructor(value: number) { this.value = value; this.next = [1]; } }
The next pointer should start as null to indicate no next node.
Fix the error in the method to set the next node pointer.
class Node { value: number; next: Node | null; constructor(value: number) { this.value = value; this.next = null; } setNext(node: Node | null): void { this.next = [1]; } }
The method should assign the passed node parameter to this.next.
Fill both blanks to create a method that returns true if the node has a next node.
class Node { value: number; next: Node | null; constructor(value: number) { this.value = value; this.next = null; } hasNext(): boolean { return this.next [1] [2]; } }
The method checks if this.next is not equal to null to confirm a next node exists.
Fill all three blanks to implement a method that inserts a new node after the current node.
class Node { value: number; next: Node | null; constructor(value: number) { this.value = value; this.next = null; } insertAfter(newNode: Node): void { newNode.next = this.[1]; this.[2] = newNode; } }
The method sets newNode.next to the current node's next, then updates this.next to newNode.
