Exemple #1
0
        public Form1()
        {
            InitializeComponent();

            {
                //Objects for the sorting classes
                InsertionSort insert = new InsertionSort();
                MergeSort     m      = new MergeSort();
                HeapSort      h      = new HeapSort();
                QuickSort     q      = new QuickSort();
                Print         p      = new Print();



                //rng declaration
                //   Random ran = new Random();

                //holds the size of the array
                //int x = 0; //ran.nextInt(6) + 5;

                //holds the choice of the user for which sorting method to use
                //  char c = ' ';



                //asks the user how long the array should be, and gets their input
                //  System.Console.WriteLine("How many numbers should be sorted? \n10, 100, 1000, 10000, 100000, 1000000 or 10000000");
                //   x = Int32.Parse(Console.ReadLine());

                //declares the array to be sorted
                //   int[] array = new int[x];



                //generates the values for the array
                // for (int i = 0; i < x; i++)
                //      {

                //       array[i] = ran.Next(10001);

                //   }

                //Sentinel for the loop. If the user enters a valid choice s becomes false and lets the loop end.
                //  bool s = true;


                /*
                 * while (s)
                 * { //loop, used to ensure that the user enters a valid value. If he does then the loop will be allowed to end
                 *
                 *  //asks the user which sorting method to use
                 *  System.Console.WriteLine("Please select a sorting method: \nEnter 1 for insertion, 2 for merge, 3 for heap, 4 for quick");
                 *  c = (char)System.Console.Read();
                 *
                 *  if (c == '1')
                 *  {
                 *     insert.insertionSortAsync(array); //uses insertion sort
                 *      s = false; //lets the loop end
                 *  }
                 *  else if (c == '2')
                 *  {
                 *      m.mergeSortAsync(array); //uses mergesort
                 *      s = false;
                 *  }
                 *  else if (c == '3')
                 *  {
                 *      h.heapsortAsync(array); //uses heapsort
                 *      s = false;
                 *  }
                 *  else if (c == '4')
                 *  {
                 *      q.quicksortAsync(array); //uses quicksort
                 *      s = false;
                 *
                 *  }
                 *  else
                 *  {
                 *      System.Console.WriteLine("You messed up, go again."); //tells the user they did not enter a valid value for sorting
                 *  }
                 *
                 * }
                 *
                 * if (x == 10)
                 * {
                 *  p.print(array); //prints the array if it is ten long
                 * }
                 *
                 * System.Console.WriteLine("Done!");
                 * }
                 *
                 */
            }
        }
Exemple #2
0
        private void QuickSortButton_Click(object sender, EventArgs e)
        {
            var quick = new QuickSort <SortedItem>(items);

            BttnSort_Click(quick);
        }