010. Assume that the node of a linked list is in the usual info link form with t
ID: 3594399 • Letter: 0
Question
010. Assume that the node of a linked list is in the usual info link form with the info of type int·list and ptr the usual info-link are pointers of type nodeType.) The following code creates a linked list: ptr new nodeType: ptr->info-16; list- new nodeType; list-info 25 ist->link ptr ptr new nodeType; ptr->info = 12; ptr->link nullptr; list-alink->link ptr; Use the linked list created by this code to answer the following questions CThese questions are independent of each other) Declare additional pointers if you need them. a Which pointer points to the first node of the linked list? b Determine the order of the nodes of the linked list c. Write a C++ code that creates and inserts a node with info 45 after the node with info 16. d Write a C++ code that creates and inserts a node with info 58 before the node with info 25. Does this require you to the change the value of the pointer that was pointing to the first node of the linked list? e Write a C++ code that deletes the node with info 25. Does this require you to the change the value of the pointer that was pointing to the first node of the linked list?Explanation / Answer
//Please see the answer below:
ptr=new nodeType;
ptr->info=16; //16
list=new nodeType;
list->info=25;
list->link=ptr; //25->16
ptr=new nodeType;
ptr->info=12;
ptr->link=nullptr;
list->link->link=ptr; //25->16->12
a) list ptr points to the first node of the linked list.
b) 25->16->12->nullptr.
c) //insert node 45 after the node with info 16;
temp=new nodeType;
temp->info=45
list->link->link=tmp;
temp->link=ptr;
New Linked list is 25->16->45->12->nullptr
d) Yes, It's require to change the value of the pointer that was pointing to the first node.
temp=new nodeType;
temp->info=25;
temp->link=list
list=temp
e) Base linked list is 25->16->12->nullptr
Now if we delete the node with value 25 then we need to change the value of the pointer that was pointing to the first node of the linked list
tmp=list->link;
delete list;
list=tmp;
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.