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

Hey guys, needs some las minute help, I have about an hour left. I wrote the cod

ID: 639106 • Letter: H

Question

Hey guys, needs some las minute help, I have about an hour left. I wrote the code below. Anyway, here's the assignment description and below is my code (c++11).]

Here is my error:

rite a C++ function to find the maximum value in a linked list. The function takes one argument - the head of the linked list. The function should traverse through the linked list, find the maximum value and then return the maximum value.

int LinkedListFindMax(node *head);

The linked list structure:

struct node

{

________________________________________________________

My code:

int LinkedListFindMax(node *head)
{
int max =0;
while (head->next != NULL)
{
head = head->next;
if (head->value > max)
{ max = head->value; }
}
return max;
}

Thanks!!!

Explanation / Answer

Hey, make head != NULL in while, not head->next != NULL

____________________________________________________________________________________

int LinkedListFindMax(node *head){
   int max = 0;
   while (head != NULL){
       if (head->value > max){
           max = head->value;
       }
       head = head->next;
   }
   return max;
}