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

7. Make a maxNode function which is a recursive function (no credit with a loop)

ID: 644140 • Letter: 7

Question

  

  

  

  

7. Make a maxNode function which is a recursive function (no credit with a loop). The maxNode function will accept a pointer of a ListNode as a parameter and return the maximum value of the list. The largestNode member function will call the maxNode member function. Your function is No an in - line function, i.e., you should define the destructor in the Implementation cpp file. #ifndef NUMBERLIST_H #define NUMBERLIST_H class NumberList { private: //declare a structure for the list struct ListNode { double value; // the value in this node struct ListNode*next; // to point to the next node }; ListNode *head; // List head pointer public: NumberList() {head = NULL;} ~NumberList(); NumberList(const NumberList &) //linked list operations void appendNode(double); void insertNode(double); void deleteNode(double); void displayList() const; double maxNode() const {return countNodes(head);} }; #endif //Question:

Explanation / Answer

double maxNode(ListNode *head){
   if(head->next == NULL)
   return head->value;
   double Max = maxNode(head->next);
   return head->value>Max?Max:head->value;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote