예제 #1
0
        static void Main(string[] args)
        {
            Childrens Ex = new Childrens();
            Stopwatch sw = new Stopwatch();

            sw.Start();

            int swap = 0;

            //выведем на экран исходный массив
            for (int i = 0; i < Ex.a.Length; i++)
            {
                Console.Write(Ex.a[i] + ", ");
            }
            //сортировка пузырьком
            for (int i = 0; i < Ex.a.Length - 1; i++)
            {
                for (int j = i + 1; j < Ex.a.Length; j++)
                {
                    if (Ex.a[i] > Ex.a[j])
                    {
                        Ex.Swap(i, j);
                    }
                    swap++;
                }
                if (swap == 0)
                {
                    break;
                }
            }
            //выводим результат массив
            Console.WriteLine();

            for (int i = 0; i < Ex.a.Length; i++)
            {
                Console.Write(Ex.a[i] + ", ");
            }

            TimeSpan ts          = sw.Elapsed;
            string   elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                                                 ts.Hours, ts.Minutes, ts.Seconds,
                                                 ts.Milliseconds / 10);

            Console.WriteLine("RunTime " + elapsedTime);
        }