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

1. Show what is produced by the following C++ code. Assume the node is in the us

ID: 3551783 • Letter: 1

Question

1. Show what is produced by the following C++ code. Assume the node is in the usual info-link

form with the info of the type int. (list, trail, and current are pointers of type nodeType.)


list = new nodeType;

list -> info = 28;

trail = new nodeType;

trail -> info = 33;

trail -> link = list;

list -> link = NULL;

current = new nodeType;

current -> info = 62;

trail -> link = current;

current ->link = list;

list= trail;

current = list ->link;

trail = current -> link

cout << list -> info<<

Explanation / Answer

1.


list = new nodeType; //creates list as new nodeType

list -> info = 28; //info field of the list is set to 28

trail = new nodeType; //creates trail as new nodeType

trail -> info = 33; //info field of the trail is set to 33

trail -> link = list; //makes the list as next node to trail

list -> link = NULL; // makes list as last node

current = new nodeType; //creates current as new nodeType

current -> info = 62; //info field of the current is set to 62

trail -> link = current; // makes current as the next node of trail

current ->link = list; // makes list as next node to current

list= trail; //assigns trail to list

current = list ->link; // assigns current node to next node of list

trail = current -> link // assigns trail to next node of current

cout << list -> info<<