1. Show what is produced by the following C++ code. Assume the node is in the us
ID: 3658908 • 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
list = new nodeType; // List is a pointer to a nodeType structure list->info = 20; // List->info is being set to 20 ptr = new nodeType; // Ptr is a pointer to a nodeType structure ptr->info = 28; // Ptr->info is being set to 28 ptr->link = NULL; // Ptr's next link is set to NULL list->link = ptr; // Link's next link is set to ptr So we have a list (head) // which contains 20 and a pointer to the next node which // contains 28 ptr = new nodeType; ptr->info = 30; ptr->link = list; list = ptr; ptr = new nodeType; ptr->info = 42; // Little hint! Be careful with this one!!! ptr->link = list->link; list->link = ptr; ptr = List; while (ptr != NULL) { coutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.