你是搞研究还是做项目?如果是搞研究,不可能。如果是做项目,这样最方便了:
int[] temps = { 10, 22, 4, 50, 100, 65, 56, 98, 105, 200, 900, 1 };
List<int> l = new List<int>(temps);
l.Sort();
temps = l.ToArray();

解决方案 »

  1.   

    這樣算嗎?
    int[] temps = { 10, 22, 4, 50, 100, 65, 56, 98, 105, 200, 900, 1 };
                for (int i = 1; i < temps.Length; i++)
                {
                    int a = temps[i-1];
                    if (temps[i] < temps[i - 1])
                    {
                        temps[i - 1] = temps[i];
                        temps[i] = a;
                        i = 0;
                    }
                }
    其實與兩層迴圈意思是一樣的,只是用一層來重覆比較。可以嗎?
      

  2.   


    如果LZ是要找排序算法我感觉快速排序算法不算递归看上去符合LZ的描述点
      

  3.   

    http://zh.wikipedia.org/wiki/%E6%8E%92%E5%BA%8F%E7%AE%97%E6%B3%95
      

  4.   

    这个是可以有的。
    这里的一次循环并不是说时间复杂度就是O(n),冒泡排序的时间复杂度肯定是O(n2)的。
    这道题考的只是一个编程技巧而已。
    一直想写篇博客来着,不过没时间写。        //two loops
            static void Sort(int[] array)
            {
                int length = array.Length;
                for (int i = 0; i < length - 1; i++)
                {
                    for (int j = 0; j < length - 1 - i; j++)
                    {
                        if (array[j] > array[j + 1])
                        {
                            int temp = array[j];
                            array[j] = array[j + 1];
                            array[j + 1] = temp;
                        }
                    }
                }
            }        //one loop
            static void SortOneLoop(int[] array)
            {
                int length = array.Length;
                int total = length * length - 1;            while (total / length > 0)
                {
                    if (total % length >= length - total / length && array[total % length] < array[total % length - 1])
                    {
                        int temp = array[total % length];
                        array[total % length] = array[total % length - 1];
                        array[total % length - 1] = temp;
                    }                total--;
                }
            }
      

  5.   

    http://www.cnblogs.com/CSharpSPF/archive/2012/03/14/2396728.html
    博客也写了一下,可以去看看。
      

  6.   

    谁说循环一次不行            int[] temps = { 10, 22, 4, 50, 100, 65, 56, 98, 105, 200, 900, 1 };
                int[] result = new int[1000];
                for (int i = 0; i < temps.Length; i++)
                {
                    result[temps[i]] = temps[i];
                }
                for (int i = 0; i < result.Length; i++)
                {
                    if (result[i]!=0) Console.WriteLine(result[i]);
                }
      

  7.   

    只循环一遍...其实你建立一个 (On2) 的循环不是一样的么...
    ( ⊙ o ⊙ )
      

  8.   

    //int[] strAry = { 1, 5, 2, 4, 9, 6, 8, 10, 20, 16, 30, 11, 11 };
            //var query =
            //    from vall in strAry
            //    orderby vall descending
            //    select vall;
            //foreach(int s in query)
            //{
            //    Response.Write(s.ToString() + "-");
            //}Linq 也 可以. . .....
      

  9.   

    11楼的方法学习了。
    不要一味拘泥于“实用性”。如果只知道3楼的写法,充其量只是熟悉api的用法而已。11楼的方法看似无用,却能拓展思维。长远来说,这更重要
      

  10.   

    如果要卖弄一些“技巧”,并且非要说这样就是一个循环,我可以给出通用解法。但是如果你的老师把这个看成什么值得拿来玩弄的东西,我只能说他很低级。for (int i = 0; i < 10; i++)
        for (int j = 0; j < 10; j++)
            Console.WriteLine("i = {0}, j = {0}", i, j);
    =>
    for (int i = 0, j = 0; i < 10; i += (((j = (++j % 10)) == 0) ? 1 : 0))
        Console.WriteLine("i = {0}, j = {0}", i, j);
      

  11.   

    我声明一下 为什么会有这种想法 ,我是参加一次技术讲座时 无意听到的,因当时也不认识对方,而且有事急着走,在公交车上好好思考了很久,技术有限,回去后冥思苦想、百度、谷歌 大神 都拜访过,也没找到特别有价值的,只能来CSDN 请教大能了,是否有最终答案已经不重要了,只是想看看大家的思路
      

  12.   


    int bubble_sort(char * array, int n)
    {
    int i=0;
    char temp;
    int count = n; while(count--)
    {
    if(*(array+i) > *(array+i+1))
    {
    temp = *(array+i);
    *(array+i) = *(array+i+1);
    *(array+i+1) = temp;
    } i++; if(i == n-1)
    {
    count = --n;
    i = 0;
    }
    }
    }