【发布时间】:2017-06-07 18:56:06
【问题描述】:
最近获得了一个冒泡排序算法,并决定尝试一个合并排序算法,我正在尝试从头开始编写它作为个人挑战,但我觉得我的逻辑在其中存在根本缺陷,不知道还有哪里可以寻求建议,我欢迎任何意见。我觉得 C# 不喜欢我声明的子数组,它们似乎也是一个不恰当的解决方案
public static void MergeSort(int[] A) // WIP
{
if (A.Length % 2 == 0 ) //Checks if input array is even
{
int[] B; //Declares sub array
int[] C; //Declares sub array
for (int x = 0; x < A.Length ; x++) //Performs an action for every item item in the array
{
if (x < A.Length / 2) //selects the first half of the input array and assigns it to sub-Array B
{
B[x] = A[x];
}
if(x > A.Length / 2) //Selects the second half of the input array and assigns it to sub-Array C
{
C[x] = A[x];
}
}
}
【问题讨论】:
-
这种问题很适合Code Review。