please follow instructions for question 23 and answer this asap. make sure your
ID: 3726591 • Letter: P
Question
please follow instructions for question 23 and answer this asap. make sure your answer is correct and I promise to give you a thumbs up
23) FOR THE LINKED LIST BELOW, CHANGE TO MAKE secondPtr the first node and head the second node. Also make it a doubly linked list. Note: you just have to change links. 10 points double value; ListNode *next; ListNode *prev; int main() ListNode *head head = new ListNode; head->value = 12.5; head->next = NULL; ListNode *secondPtr = new ListNode; secondPtr->value = 13.5; secondPtr->next = NULL; head->next = secondPtr;Explanation / Answer
With pertaining to the question that is given below I am writing the code that has to be written inside main().
So after head->next = secondPtr write this :
head -> next = NULL; //change the next pointer of head from secondPtr to NULL, meaning the next of head now points to NULL
secondPtr -> next = head; //change the next pointer of secondPtr from NULL to head, meaning the next of secondPtr now points to head;
// Now to add the second link,: we now have already established the situation where the node secondPtr is the start node which is followed by head, so we'll make the previous pointer of head point to seconPtr and that of the secondPtr point to NULL(as it is the beginning/first node now)
head->prev = secondPtr;
secondPtr->prev = NULL;
_______________________________________________________________________________________
Note : now that your first node is secondPtr, if you further add more nodes and then intend to perform a scan operation across the list then make sure to start your loop with secondPtr.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.