Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Use the Java code below to draw the diagram and identify the values of the va

ID: 3685608 • Letter: 1

Question

1. Use the Java code below to draw the diagram and identify the values of the variables/expressions that follow. The value may be undefined, or the expression may be invalid. NOTE: For this exercise, each node has 3 components (number-character-link).

    LinkedListNode current = new LinkedListNode();
    LinkedListNode last;

    current.number = 37;
    current.character = 'z';
    current.link = new LinkedListNode();
    last = current.link;
    last.number = 9;


    LinkedListNode first = new LinkedListNode();
    last.link = first;
    first.number = 9;
    first.character = 'h';
    first.link = current;

Expression:

1) first.link.number

2) first.link.link.character
3) first.link == last
4) current.link.number
5) first == last.link
6) first.number < first.link.number

Explanation / Answer

current [37, ‘z’] -> last[9] -> first [9, ‘h’] -> current

1) Since

LinkedListNode first = new LinkedListNode();

first.link = current;

current.number = 37;

hence first.link.number is 37

2) Since first.link.link is last but last has no character hence answer is nothing. I mean blank

3) false (because first.link is current)

4) 9 (Since current.link is last and last.number is 9)

5) true (see 1st line diagram)

6) true (since first.number = 9 and first.link.number = 37)