Week 6: Optional Exercises

1. List Length

Write a function that determines the length of a linked list.

2. List Append

Write a procedure that appends a number to a linked list.

3. Second To Last

Write a function that returns the second-to-last element of a linked list of non-negative integers. If there is no such element, return -1.

4. No First or Third

Write a procedure that deletes the first element (if any) and the third element (if any) of a linked list.

5. Delete the Nth

Write a procedure that deletes the Nth element (if any) of a linked list.

6. Delete Every Other

Write a procedure that deletes every other element of a linked list, starting with the first.

7. Flip It

Write a function or procedure that reverses a linked list. Do not allocate any additional memory.

8. Sorted Insert

Write a procedure that inserts an integer into a sorted linked list.

9. Multiple Delete

Write a procedure that deletes all occurrences of an integer from a sorted linked list.

10. Smooth It

Write a procedure that “smooths” a linked list by averaging each value with the following value (if any) and preceding value (if any).

11. Even/Odd Split

Write a function that splits a linked list into two lists, one containing even numbers, one odd. The numbers in each list should appear in the same order as in the original list.