Now question below is from a written test / interview
Question:
public void MergeSort(List list, int low, int high)
{
int temp;
if (low == high)
{
return;
}
if (high - low == 1)
{
if (list[low] > list[high])
{
temp = list[low];
list[low] = list[high];
list[high] = temp;
}
}
else
{
int mid = high + low / 2;
MergeSort(list, low, mid);
MergeSort(list, mid + 1, high);
}
}
a. run time exception
b. Will completely sort the list
c. Will partially sort the list
Answer: Stackoverflow exception, recursive call is going for an infinite loop.....
also please do comment if any other answers
Friday, January 11, 2008
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment