Algorithm MergeSort(low, high)
//a[low:high] is a global array to be sorted
//small(P) is true if there is only one element to
//sort.In this case the list is already sorted
{
if(low<high) // If there are more than one element
{
//Divide P into subproblems.
Find where to split the set
mid = (low+high)/2;
//solve the subproblems.
MergeSort(low,mid);
MergeSort(mid+1, high);
//Combine the Solutions.
Merge(low, mid, high);
}
}
//a[low:high] is a global array to be sorted
//small(P) is true if there is only one element to
//sort.In this case the list is already sorted
{
if(low<high) // If there are more than one element
{
//Divide P into subproblems.
Find where to split the set
mid = (low+high)/2;
//solve the subproblems.
MergeSort(low,mid);
MergeSort(mid+1, high);
//Combine the Solutions.
Merge(low, mid, high);
}
}
No comments:
Post a Comment