Assume that the node of a linked list is in the usual info-1ink form with the in
ID: 3909772 • Letter: A
Question
Assume that the node of a linked list is in the usual info-1ink form with the info of type int. (list and ptr are pointers of type nodeType. The following code creates a linked list: ptr- new nodeType; ptr->info 16 list = new nodeType; list-> info = 25; list->1link ptr; ptr = new nodeType ; ptr->info = 12; ptr->link nullptr; list->link->link ptr; Use the linked list created by this code to answer the following questions. These questions are independent of each other.) Declare additional pointers if you need them. (3, 4)Explanation / Answer
After the code, list will look like below.. 25 -> 16 -> 12 list points to node 25. (Head) ptr points to node 12. (Tail) 1) nodeType *ptr1 = new nodeType; ptr1->info = 45; ptr1->link = list->link->link; list->link->link = ptr1; 2) nodeType *ptr1 = new nodeType; ptr1->info = 58; ptr1->link = list; // It doesnt require to change list node in order to add this node at beginning // but in case, if we always want to track the first node with list pointer, then yes, // we need to change that.. // i am making the change here. list = ptr1; 3) nodeType *ptr1 = list->next; list->next = ptr1->next; delete ptr1; // it doesnt require to change the list pointer, as it is pointing to first node of list, while // we are deleting the second node of the list
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.