Question: Linked List - Find Largest - use Recursion Write the body for the largest function: T largest(Node* current) It should get the largest value in

Linked List - Find Largest - use Recursion

Write the body for the largest function:

T largest(Node* current)

It should get the largest value in the list starting at current. You may assume that the function will not be passed a nullptr. Hints:

  • You can declare a temporary of type T. If you have to initialize it to a default value (you shouldn't need to...) use something like
    T temp{};
    with curly braces showing an empty initialization list.

Code:

Linked List - Find Largest - use Recursion Write the body for

1-#include 3 using namespace std; 5 template typename T 6, class Node { 7 public: //Value stored in this node T element; //Next node in list (nullptrend of list) Node* next nullptr; 10 12 13 14 15 16 17 18 template //Node must be constructed with a value stored as element Node (T value : element (value) (h 9 largest(NodeT* current) 20 //Do not modify anything on or above the line below this 21 //YOUR CODE BELOW 23 24 5 /yOUR CODE ABOVE 26 //Do not modify anything on or below the line above this 27 28 29 30 int main) 31 32 //YOUR CODE Node* head = new Node char>( 'B' ); char largestVal largest (head) ; cout next . new Node(' N' ); head->next->next-new Node('A' largestVallargest (head); cout next->next->nextnew Nodecchar> ('R) largestVal - largest (head); cout

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!