Пример #1
0
        private void BtnBasicSort_Click(object sender, EventArgs e)
        {
            var cArray = new CArray(this, 10, true);

            cArray.DisplayElements();
            cArray.SelectionSort();
            cArray.DisplayElements();
        }
Пример #2
0
        static void Main()
        {
            // CArray nums = new CArray(10);
            // Random rnd = new Random(100);
            // for(int i = 0; i < 10; i++)
            //     nums.Insert((int)(rnd.NextDouble() * 100));
            // nums.DisplayElements();

            // Console.WriteLine("Before sorting: \n");
            // nums.DisplayElements();
            // Console.WriteLine("During sorting: \n");
            // //nums.BubbleSort();
            // //nums.SelectionSort();
            // nums.InsertionSort();
            // Console.WriteLine("After sorting: \n");
            // nums.DisplayElements();

            Timing sortTime = new Timing();
            Random rnd      = new Random(100);
            int    numItems = 10000;
            CArray theArray = new CArray(numItems);

            for (int i = 0; i < numItems; i++)
            {
                theArray.Insert((int)(rnd.NextDouble() * 100));
            }
            sortTime.startTime();
            theArray.SelectionSort();
            sortTime.stopTime();
            Console.WriteLine("Time for Selection sort: " +
                              sortTime.Result().TotalMilliseconds);

            theArray.Clear();

            for (int i = 0; i < numItems; i++)
            {
                theArray.Insert((int)(rnd.NextDouble() * 100));
            }
            sortTime.startTime();
            theArray.BubbleSort();
            sortTime.stopTime();
            Console.WriteLine("Time for Bubble sort: " +
                              sortTime.Result().
                              TotalMilliseconds);

            theArray.Clear();

            for (int i = 0; i < numItems; i++)
            {
                theArray.Insert((int)(rnd.NextDouble() * 100));
            }
            sortTime.startTime();
            theArray.InsertionSort();
            sortTime.stopTime();
            Console.WriteLine("Time for Insertion sort: " +
                              sortTime.Result().
                              TotalMilliseconds);
        }
Пример #3
0
        static void Main(string[] args)
        {
            CArray cArray = new CArray(10);
            Random rnd    = new Random(100);

            for (int i = 0; i < 10; i++)
            {
                cArray.Insert(rnd.Next(0, 1000));
            }
            Console.WriteLine("Before Sorting:");
            cArray.DisplayElements();
            Console.WriteLine("During Sorting:");
            cArray.SelectionSort();
            Console.WriteLine("After Sorting:");
            cArray.DisplayElements();
            Console.ReadKey();
        }