The parameter to the following two recursive routines is a p
Solution
Part A
Node* MinLoc (Node* Current) {
Node* NN = Current->next;
if (Current->next == NULL) {
//The value at this node is obviously smaller than a non-existent value
return Current;
}
else
{
//Recur to find the smallest value from the rest of the linked list
NN = MinLoc(Current->next);
}
//Return the smallest value between this node and the end of the list
if (Current->value < NN->value)
{
return Current;
}
else
{
return NN;
}
}
Part B
void Sort(Node *Current)
{
int temp_val; //Temporary variable for swapping data
Node *Repl; //Temporary node to receive the return value of the function MinLoc
if(Current->next==NULL)
{
exit(0);
}
else
{
Repl = MinLoc(Current);
temp_val = Repl->value;
Repl->value = Current->value;
Current->value = temp_val;
Sort(Current->next);
}
}
