A linked list stores animal names in alphabetical order. (c)(ii) To delete a data item, the algorithm has special cases; one is that the list is empty. Describe two other special cases. (d) Describe how the data item 'BAT' is inserted into the linked list.
Points that gain marks
- (c)(ii) The item is not in the list.
- The item is the only item in the list, or the first item in the list.
- (d) Store 'BAT' at the next free location in the Data array.
- Start at the node the start pointer points to and compare 'BAT' with its data ('ANT').
- If 'BAT' is not less than it, remember this position and move to the next node ('BISON'); repeat until 'BAT' is less than the current value.
- Point the previous node ('ANT') to 'BAT' …
- … and point 'BAT' to the current node ('BISON').
In this lab: 'Insert in order' walks the list and moves the two pointers; 'Delete a node' and 'A new first node' are the special cases.