常用的asp.net代码,发出来 学习了,先谢谢大家了!

解决方案 »

  1.   

    //冒泡排序   
    class EbullitionSorter   
    {   
        public void Sort(int[] arr)   
        {   
            int i, j, temp;   
            bool done = false;   
            j = 1;   
            while ((j < arr.Length) && (!done))//判断长度   
            {   
                done = true;   
                for (i = 0; i < arr.Length - j; i++)   
                {   
                    if (arr[i] > arr[i + 1])   
                    {   
                        done = false;   
                        temp = arr[i];   
                        arr[i] = arr[i + 1];//交换数据   
                        arr[i + 1] = temp;   
                    }   
                }   
                j++;   
            }   
        }   
      
        static void Main(string[] args)   
        {   
            int[] array = new int[] { 1, 5, 3, 6, 10, 55, 9, 2, 87, 12, 34, 75, 33, 47 };   
            EbullitionSorter e = new EbullitionSorter ();   
            e.Sort(array);   
            foreach (int m in array)   
                Console.WriteLine("{0}", m);   
      
        }   
      

  2.   

    //插入排序   
    public class InsertionSorter   
    {   
        public void Sort(int[] arr)   
        {   
            for (int i = 1; i < arr.Length; i++)   
            {   
                int t = arr[i];   
                int j = i;   
                while ((j > 0) && (arr[j - 1] > t))   
                {   
                    arr[j] = arr[j - 1];//交换顺序   
                    --j;   
                }   
                arr[j] = t;   
            }   
        }   
        static void Main(string[] args)   
        {   
            int[] array = new int[] { 1, 5, 3, 6, 10, 55, 9, 2, 87, 12, 34, 75, 33, 47 };   
            InsertionSorter i = new InsertionSorter();   
            i.Sort(array);   
            foreach (int m in array)   
                Console.WriteLine("{0}", m);    
        }   
    }   
      

  3.   

    http://hi.baidu.com/hyz1985/blog/item/0b0ce28833c1a293a5c2722b.html