算法排序

1.C#传数组是属于传地址不属于传值

  2.使用return时,返回的是上一级调用函数的地方。若是递归则向上一级。不会跳出整个函数。

2009.10.26

算法排序

public class paixun
    {
        //冒泡排序
        public string[] maopao(string[] list)
        {
            string temp;
            for (int j = 0; j < list.Length - 1;j++)
            {
                for (int i = 0; i < list.Length-1; i++)
                    {
                        if (int.Parse(list[i]) > int.Parse(list[i + 1]))
                        {
                            temp = list[i];
                            list[i] = list[i + 1];
                            list[i + 1] = temp;
                        }
                    }
             }
            return list;
        }
      
        //快速排序
        public int kuaisuhelp(string[] list,int low,int high)
        {
            string temp = list[low];
            int i = low;
            int j = high;
            while (i < j)
            {
                while (int.Parse(list[j]) >= int.Parse(temp) && i < j)
                    j--;          
                list[i] = list[j];
                while (int.Parse(list[i]) <= int.Parse(temp) && i < j)
                    i++;
                list[j] = list[i];
            }
            list[i] = temp;
           
            return i;
         }

        public void kuaisu(string[] list, int low, int high)
        {
            if (low >= high) return; 
            int _nPivotIndex = kuaisuhelp(list,low,high);
            kuaisu(list, low, _nPivotIndex-1);
            kuaisu(list, _nPivotIndex + 1,high);
        }
    }

posted on 2011-08-23 14:33  linfenglee  阅读(92)  评论(0)    收藏  举报

导航