c++里面的排序还算熟悉,c#里面的排序就比较迷糊了,大侠帮忙:怎么用c#实现选择排序算法

解决方案 »

  1.   

    MSDN……语法这个不是特别重要思想……
    up^^
      

  2.   

    //输出演示(C#)
    public static void SelectionSort<T, C>(T[] array, C comparer)
        where C : IComparer<T> 
    {
        int length = array.Length;
        for (int i = 0; i <= length - 2; i++) {
            Console.Write("{0}: ", i+1);
            int lowestIndex = i;        // 最小记录的数组索引
            for (int j = length - 1; j > i; j--) {
                if (comparer.Compare(array[j], array[lowestIndex]) < 0)
                    lowestIndex = j;
            }
            swap(ref array[i], ref array[lowestIndex]);
            AlgorithmHelper.PrintArray(array);
        }
    }
    static void Main(string[] args) {
        int[] array = {42,20,17,13,28,14,23,15};
        AlgorithmHelper.PrintArray(array);    SortAlgorithm.SelectionSort
            (array, ComparerFactory.GetIntComparer());
    }详细请看我的博客
    四种简单的排序算法
      

  3.   

    http://blog.csdn.net/hustcyb/archive/2008/09/13/2923086.aspx
    C#算法请参考我的博客
    http://blog.csdn.net/hustcyb
      

  4.   

    是否可以考虑把排序字段传入到查询语句里面去,通过 sql查询直接处理。