All lessonsOpen Open Open Open Open
3. Linked Lists
Insert and delete
0 of 5 activities0%
Reading 1
Pointer rewiring
Insert at head: newNode->next = head; head = newNode;
Insert after a node: newNode->next = cur->next; cur->next = newNode;
Delete head: Node* t=head; head=head->next; delete t;
Delete after prev: Node* t=prev->next; prev->next=t->next; delete t;
Never lose the only pointer to a node you still need.
Check 2
Insert front cost
Inserting at the head of a singly linked list is
Fill in 3
Remove
Try it 4
Push front
Insert 0 at front.
main.cpp
Loading editor…
Output will appear here.
Assignment 5
Delete head value
Build list from n ints. Delete the head node if the list is non-empty, then print remaining values separated by spaces (or print empty line if none).
main.cpp
Loading editor…