Complete the code to delete the first node of the linked list.
head = head.[1];To delete the first node, we move the head pointer to the next node.
Complete the code to check if the linked list is empty before deleting the first node.
if (head == [1]) { return; } head = head.next;
We check if head is null to know if the list is empty.
Fix the error in the code to properly delete the first node and update the tail if needed.
if (head == null) { return; } head = head.next; if (head == [1]) { tail = null; }
After deleting the first node, if head becomes null, the list is empty, so tail should be set to null.
Fill both blanks to complete the method that deletes the first node and returns its value.
public int DeleteFirst() {
if (head == [1]) {
throw new InvalidOperationException("List is empty");
}
int value = head.[2];
head = head.next;
if (head == null) {
tail = null;
}
return value;
}Check if head is null to detect empty list. The node's stored value is in 'data'.
Fill all three blanks to complete the method that deletes the first node and updates the list correctly.
public void DeleteFirstNode() {
if (head == [1]) {
return;
}
Node temp = head;
head = head.[2];
temp.[3] = null;
if (head == null) {
tail = null;
}
}Check if head is null to avoid deleting from empty list. Move head to next node. Disconnect old head's next pointer.
