I have created a function that is supposed to take the numbers in my linked list and determine which one is the smallest number and which one is the largest number. I created a
You forgot to step through the list. Using on of the solutions for the average:
void NumberSize(NewNumber * start)
{
double num = 0.0;
double biggest;
double smallest;
int flag = 0;
NewNumber *temp = start;
// set start values
if(tmp != NULL){
biggest = temp->newNum;
smallest = temp->newNum;
tmp = tmp->next;
flag = 1;
}
// while temp is not NULL
while (temp) {
// get number from current node
num = temp->newNum;
// if that number is bigger than "biggest"
if (num > biggest) {
// exchange "biggest" with "num"
biggest = num;
}
// do it the same way for the smallest number
else if (num < smallest) {
smallest = num;
}
// here is the forgotten line:
// go to the next node
temp = temp->next;
}
if(flag){
// no returns, just printing
printf("The smallest number is: \n", smallest);
printf("The biggest number is: \n", biggest);
} else {
puts("list empty");
}
}