Complete the code to delete the first node of a singly linked list.
if (this.head !== null) { this.head = this.head[1]; }
The head pointer should move to the next node to delete the first node.
Complete the code to check if the list is empty before deleting the first node.
if (this.head [1] null) { this.head = this.head.next; }
We delete the first node only if head is not null (list is not empty).
Fix the error in the delete method to correctly update the head pointer.
deleteFirst() {
if (this.head !== null) {
this.head = this.head[1];
}
}The head should be updated to the next node to remove the first node.
Fill both blanks to delete the first node and handle empty list correctly.
deleteFirst() {
if (this.head [1] null) {
this.head = this.head[2];
}
}Check head is not null, then update head to head.next to delete first node.
Fill all three blanks to implement deleteFirst method that updates head and returns deleted node's value or null if empty.
deleteFirst(): number | null {
if (this.head [1] null) {
const deletedValue = this.head.value;
this.head = this.head[2];
return [3];
}
return null;
}Check head is not null, save value, update head to next node, then return saved value.
