For this homework, you may assume the type definitions used in class today:
struct NodeType {
int i;
NodeType *Next;
};
NodeType *Head;
Write a function to find the maximum and minimum values stored in an unsorted linked list. Use the following prototype:
void MaxMin ( int &Max, int &Min );
void MaxMin ( int &Max, int &Min )
{
if (Head == NULL)
{
Max = 1;
Min = 2;
return;
}
Max = Head->i;
Min = Head->i;
NodeType *p = Head->Next;
while (p != NULL)
{
if (p->i < Min)
Min = p->i;
if (p->i > Max)
Max = p->i;
p = p->Next;
}
}