THIS LINKED LIST BELOW HAS 2 NODES. WRITE THE STATEMENTS TO INSERTATHIRD NODE BE
ID: 3843351 • Letter: T
Question
THIS LINKED LIST BELOW HAS 2 NODES. WRITE THE STATEMENTS TO INSERTATHIRD NODE BETWEEN THE FIRST AND SECOND NODES. CALLTHE NEW NODE MIDDLE, AND ASSIGN VALUE 13.0. Put your answer to the right below this line. #include using namespace std; struct ListNode {double value ListNode *next}; int main() {ListNode *head; head = new ListNode head- >value = 12.5; head- >next = NULL; ListNode *secondPtr = new ListNode; secondPtr rightarrow value =13.5; secondPtr rightarrow next = NULL; head- >next = second Ptr;Explanation / Answer
ListNode * middlePtr = new ListNode;
middlePtr->value = 13.0;
middlePtr->next = secondPtr; //point to second
head->next = middle; //make head point to middle , hence we added one node between them
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.