예제 #1
0
        static void Main(string[] args)
        {
            int[] myarr = { 12, 5, 40, 8, 45, 3, 1, 25, 18, 10, 2 };
            Console.WriteLine("原数组为");
            foreach (int item in myarr)
            {
                Console.Write(item + " ");
            }
            Console.WriteLine();

            Sort             st      = new Sort();
            sortEventHandler mySort1 = new sortEventHandler(st.xuanzeSort);
            sortEventHandler mySort2 = new sortEventHandler(st.maopaoSort);
            sortEventHandler mySort3 = new sortEventHandler(st.charuSort);
            sortEventHandler mySort4 = new sortEventHandler(st.shellSort);

            Console.WriteLine("选择排序");
            st.ShowResult(mySort1, myarr);

            Console.WriteLine("冒泡排序");
            st.ShowResult(mySort2, myarr);

            Console.WriteLine("快速排序");
            st.ShowResult(mySort3, myarr);

            Console.WriteLine("希尔排序");
            st.ShowResult(mySort4, myarr);

            Console.ReadLine();
        }
예제 #2
0
 //显示排序后的数组
 public void ShowResult(sortEventHandler se, int[] arr)
 {
     if (se != null)
     {
         int[] resultArr = se(arr);
         foreach (int item in resultArr)
         {
             Console.Write(item + " ");
         }
         Console.WriteLine();
     }
     else
     {
         Console.WriteLine(se + "调用列表为空");
     }
 }
예제 #3
0
        static void Main(string[] args)
        {
            int[] myarr = { 12, 5, 40, 8, 45, 3, 1, 25, 18, 10, 2 };
            Console.WriteLine("原数组为");
            foreach (int item in myarr)
            {
                Console.Write(item + " ");
            }
            Console.WriteLine();

            Sort             st      = new Sort();
            sortEventHandler mySort1 = new sortEventHandler(st.xuanzeSort);
            sortEventHandler mySort2 = new sortEventHandler(st.maopaoSort);

            Console.WriteLine("选择排序");
            if (mySort1 != null)
            {
                int[] resultArr = mySort1(myarr);
                foreach (int item in resultArr)
                {
                    Console.Write(item + " ");
                }
                Console.WriteLine();
            }
            else
            {
                Console.WriteLine("mySort1的调用列表为空");
            }

            Console.WriteLine("冒泡排序");
            if (mySort2 != null)
            {
                int[] resultArr = mySort2(myarr);
                foreach (int item in resultArr)
                {
                    Console.Write(item + " ");
                }
                Console.WriteLine();
            }
            else
            {
                Console.WriteLine("mySort2的调用列表为空");
            }

            Console.ReadLine();
        }