我试图从program.cs调用类Merge Sort但是错误一直显示项目不包含'Merge Sort'的定义,并且没有扩展方法'Merge Sort'接受类型的第一个参数可以找到'projectname.MergeSort'。下面是我对2个类的代码。任何人都可以帮忙吗?感谢
类合并排序代码:
class MergeSort
{
static public void MergeSorting(int[] array, int left, int mid, int right)
{
int[] temp = new int[25];
int i, left_end, num_elements, tmp_pos;
left_end = (mid - 1);
tmp_pos = left;
num_elements = (right - left + 1);
while ((left <= left_end) && (mid <= right))
{
if (array[left] <= array[mid])
temp[tmp_pos++] = array[left++];
else
temp[tmp_pos++] = array[mid++];
}
while (left <= left_end)
temp[tmp_pos++] = array[left++];
while (mid <= right)
temp[tmp_pos++] = array[mid++];
for (i = 0; i < num_elements; i++)
{
array[right] = temp[right];
right--;
}
}
static public void MergeSort_Recursive(int[] array, int left, int right)
{
int mid;
if (right > left)
{
//splitting array into 2
mid = (right + left) / 2;
MergeSort_Recursive(array, left, mid);
MergeSort_Recursive(array, (mid + 1), right);
MergeSorting(array, left, (mid + 1), right);
}
}
}
类program.cs代码:
//array to be sorted
int[] array = { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0 };
//sort the array using merge sort
MergeSort mSort = new MergeSort();
int[] mergeSortedArray = mSort.MergeSort(array);