Example #1
0
        static void Main(string[] args)
        {
            const int TANTI = 20;
            Random    r     = new Random();

            int[]      array  = new int[TANTI];
            List <int> numeri = new List <int>();

            for (int i = 0; i < TANTI; i++)
            {
                int k;
                do
                {
                    k = r.Next(0, 100);
                } while (numeri.Contains(k));
                numeri.Add(k);
                array[i] = k;
            }
            Console.WriteLine("STAMPO ARRAY NON ORDINATO: ");
            for (int i = 0; i < array.Length; i++)
            {
                Console.Write(array[i] + " ");
            }
            Console.WriteLine();
            int[] sortedArray = CountingSort.Counting_Sort(array);
            Console.WriteLine("STAMPO ARRAY ORDINATO: ");
            for (int i = 0; i < TANTI; i++)
            {
                Console.Write(sortedArray[i] + " ");
            }
        }
Example #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            int[] arr = new DiziOlustur().Olustur();


            var secim = algoritmaListesi.SelectedIndex;

            if (secim == 0)
            {
                SelectionSort selectionSort = new SelectionSort(arr);
                Stopwatch     stopwatch     = new Stopwatch();
                stopwatch.Start();
                selectionSort.SelectionSortAlgoritm();
                stopwatch.Stop();
                TimeSpan sure = stopwatch.Elapsed;
                lblSelection.Text = sure.ToString();
            }
            else if (secim == 1)
            {
                InsertionSort insertionSort = new InsertionSort(arr);
                Stopwatch     stopwatch     = new Stopwatch();
                stopwatch.Start();
                insertionSort.insertion_sort();
                stopwatch.Stop();
                TimeSpan sure = stopwatch.Elapsed;
                lblInsertion.Text = sure.ToString();
            }
            else if (secim == 2)
            {
                BubbleSort bubbleSort = new BubbleSort(arr);
                Stopwatch  stopwatch  = new Stopwatch();
                stopwatch.Start();
                bubbleSort.Bubble_Sort();
                stopwatch.Stop();
                TimeSpan sure = stopwatch.Elapsed;
                lblBubble.Text = sure.ToString();
            }
            else if (secim == 3)
            {
                CountingSort countingSort = new CountingSort(arr);
                Stopwatch    stopwatch    = new Stopwatch();
                stopwatch.Start();
                countingSort.Counting_Sort();
                stopwatch.Stop();
                TimeSpan sure = stopwatch.Elapsed;
                lblCounting.Text = sure.ToString();
            }
            else if (secim == 4)
            {
                QuickSort quickSort = new QuickSort(arr);
                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();
                quickSort.sort_quick();
                stopwatch.Stop();
                TimeSpan sure = stopwatch.Elapsed;
                lblQuick.Text = sure.ToString();
            }
            else if (secim == 5)
            {
                MergeSort mergeSort = new MergeSort(arr);
                Stopwatch stopwatch = new Stopwatch();
                stopwatch.Start();
                mergeSort.sort_merge();
                stopwatch.Stop();
                TimeSpan sure = stopwatch.Elapsed;
                lblMerge.Text = sure.ToString();
            }
        }