Java Reference
In-Depth Information
3. What value is stored as the next field of the last node of a list? What value will a node's next field have if none
is specified?
4. What happens if you or the client try to go past the last element in a linked list? Be specific.
For each of the next four problems, draw a picture of what the given linked nodes would look like after the given
code executes.
5.
list
1
2
list.next = new LinkNode(3);
6.
list
1
2
list.next = new LinkNode(3, list.next);
7.
list
1
2
3
list = new LinkNode(4, list.next.next);
8.
list
1
2
3
list.next.next = null;
For each of the next nine problems, you'll see pictures of linked nodes before and after changes. Write the code that
will produce the given result by modifying links between the nodes shown and/or creating new nodes as needed.
There may be more than one way to write the code, but you may not change any existing node's data field value. If
a variable does not appear in the “after” picture, it doesn't matter what value it has after the changes are made.
Before
After
9.
list
1
2
list
1
2
3
10.
list
1
2
list
3
1
2
11.
list
1
2
list
1
3
4
2
temp
3
4
12.
list
1
2
3
list
2
list2
1
3
13.
list
5
4
3
list
4
5
3
14.
list
5
4
3
list
3
4
5
15.
list
1
2
3
list
5
3
4
2
temp
4
5
6
Search WWH ::




Custom Search