Skip to main content

Exercises 27.17 Exercises

1.

Allocate 4 list nodes on the heap containing the values 1, 2, 3, 4. Connect them in a linked list (in numerical order). Make a pointer to the first node called start.

2.

Write the removeStart function for the Simple Linked List. Make sure to delete the node from memory.

3.

Write the listSize function for the Simple Linked List. You should walk through the nodes and count them, then return the count.

4.

Finish the insertAt function for the Simple Linked List. It should insert a new node at the specified index. You do not have to worry about bad indexes.
Hint 1.
To insert at index i, you need to traverse the list to position i-1 so you can update the next pointer of the node before location i.
Hint 2.
You will have to update two next pointers when inserting a new node.

5.

Finish the removeStart function for the Linked List (with size and tail). Make sure to consider the case where there is just a single node.

6.

Finish the insertEnd function for the Linked List (with size and tail).

7.

Write the clear function for the Linked List (with size and tail).
You can copy/paste in your removeStart from ExerciseΒ 27.17.5 to help with this implementation.

8.

Write the copyFrom function for the Linked List (with size and tail).
You should use your insertEnd from ExerciseΒ 27.17.6 to simplify your implementation. You may assume the list starts out as a valid empty list.

9.

Write the constructor for the Doubly Linked List. You need to create an empty list with dummy nodes for head and tail that are connected together.
To make a new node with a dummy (default) value, you can use ListNode<T>(T{})

10.

Write the removeEnd function for the Doubly Linked List. It should remove the node before the dummy tail node. You will have to add your constructor from ExerciseΒ 27.17.9.
You have attempted of activities on this page.