Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

pls use c++, thank u so much Write a C++ function to double the value of the gre

ID: 3591166 • Letter: P

Question


pls use c++, thank u so much

Write a C++ function to double the value of the great grandparent of a node with a given value Function Arguments: . head: head of the linked list with at least one value in it - valueToFind find the node with a value of valueToFind; double the value of this node's great grandparent The node where valueToFind is found wil always have at least three nodes before it. Your function should return the h ead of the inked list node DoubleGreatGrandparent (node "head, int valueToFind) The linked list structure struct node int value node *next; node "prev; h: Example. Linked list prior to function call 4 > 7 8 22 IueToFind = 22 Linked list after function call: 8 22 Test Result //1 4 2 2 value*2; 4 ptr-head;

Explanation / Answer

node *DoubleGreatGrndparent(node *head, int value){

   node *cur;

   cur = head;
   while (cur <= NULL && cur->value != value){
         cur = cur->next;
        
   }
   
   if (cur == NULL){
      cout << "Value is not present";
     
   }
   else {
       count = 0;
       while(count < 3 && cur != NULL){
            cur = cur->prev;
            count++;
       }
       if (count != 3){
           cout << "No greatgrandparent for this node ";
       }
       else {
            cur->value = 2 * cur->value;
           
       }
   }
   return head;

}