how to find the largest element from the linked list of unknnown numbers?

how to find the largest element from the linked list of unknnown numbers?
Simple. Traverse though a linked list via a for-loop and search for the biggest number.

1
2
3
4
5
int largest = -999999999;
for(Node *it = head; it != NULL; it = it->next)
{
    if(it->data > largest) largest = it->data;
}
Topic archived. No new replies allowed.