Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 双重计数排序_C#_Sorting - Fatal编程技术网

C# 双重计数排序

C# 双重计数排序,c#,sorting,C#,Sorting,我尝试用计数排序法对两位数进行排序。尝试将所有双精度转换为整数,但由于某些原因,什么也没有发生。我对整数进行排序的代码 public static void CountingSort(DataArray items) { // O(1) int max = items[0]; // O(N) for (int i = 0; i < items.Length; i++) { if (items[i] > max) {

我尝试用计数排序法对两位数进行排序。尝试将所有双精度转换为整数,但由于某些原因,什么也没有发生。我对整数进行排序的代码

public static void CountingSort(DataArray items) {
    // O(1)
    int max = items[0];

    // O(N)
    for (int i = 0; i < items.Length; i++) {
        if (items[i] > max) {
            max = items[i];
        }
    }   

    // Space complexity O(N+K)
    int[] counts = new int[max + 1];

    // O(N)
    for (int i = 0; i < items.Length; i++) {
        counts[items[i]]++;
    }
    // O(N+K)
    int j = 0;
    int c = items.Length - 1;
    int current, previous;
    for (int i = 0; i < counts.Length; i++) {
    while (counts[i] > 0) {
        while (c > j) {
            if (items[c] == i) {
            current = items[c];
            while (c != j)
        {
        previous = items[c - 1];
        items.Swap(c, current, previous);
        c--;
        }
    }
    c--;
    }
    j++;
    counts[i]--;
    c = items.Length - 1;
    }
    }
}
公共静态void CountingSort(数据数组项){
//O(1)
int max=项目[0];
//O(N)
对于(int i=0;i最大值){
max=项目[i];
}
}   
//空间复杂度O(N+K)
int[]计数=新的int[max+1];
//O(N)
对于(int i=0;i0){
而(c>j){
如果(项目[c]==i){
当前=项目[c];
而(c!=j)
{
以前=项目[c-1];
交换项目(c、当前、以前);
c--;
}
}
c--;
}
j++;
计数[i]-;
c=项目。长度-1;
}
}
}

甚至可以使用计数排序对双位数进行排序吗?

要对双位数数组进行排序,请使用

double[] doubleArray = new double[5] { 8.1, 10.2, 2.5, 6.7, 3.3 };
doubleArray  = Array.Sort(doubleArray);
之后,使用循环进行计数