Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Timing sortTime = new Timing();
            Random rnd      = new Random(100);
            int    numItems = 6000;
            CArray theArray = new CArray(numItems);

            for (int i = 0; i < numItems; i++)
            {
                theArray.Insert((int)(rnd.NextDouble() * 100));
            }
            sortTime.Start();
            theArray.SelectionSort();
            sortTime.Stop();
            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.Start();
            theArray.BubbleSort();
            sortTime.Stop();
            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.Start();
            theArray.InsertionSort();
            sortTime.Stop();
            Console.WriteLine("Time for Insertion sort: " + sortTime.Result().TotalMilliseconds);
        }
        public void BubbleSortShowcase()
        {
            CArray nums = new CArray(10);
            Random rnd  = new Random(100);

            for (int i = 0; i < 10; i++)
            {
                nums.Insert((int)(rnd.NextDouble() * 100));
            }

            Console.WriteLine("Before sorting: ");
            nums.DisplayElements();
            Console.WriteLine("During sorting: ");
            nums.BubbleSort();
            Console.WriteLine("After sorting: ");
            nums.DisplayElements();
        }