Exemple #1
0
 public List <int> InsertionSort(List <int> inputList)
 {
     for (int i = 0; i < inputList.Count - 1; i++)
     {
         for (int j = i + 1; j > 0; j--)
         {
             if (inputList[j - 1] > inputList[j])
             {
                 Utilitys.Swap(j - 1, j, ref inputList);
             }
         }
     }
     return(inputList);
 }
Exemple #2
0
        public List <int> BubbelSort(List <int> listToSort)
        {
            bool isChanged = false;

            do
            {
                isChanged = false;
                for (int i = 1; i < listToSort.Count; i++)
                {
                    if (listToSort[i - 1] > listToSort[i])
                    {
                        Utilitys.Swap(i - 1, i, ref listToSort);
                        isChanged = true;
                    }
                }
            } while (isChanged || sortor > 20);
            return(listToSort);
        }
Exemple #3
0
        public void Run(int magic)
        {
            Stopwatch  watch   = new Stopwatch();
            List <int> amounts = new List <int>()
            {
                10, 1000, 100000
            };

            if (magic < 10)
            {
                sortor = magic;
                for (int i = 0; i < amounts.Count; i++)
                {
                    int        amount = amounts[i];
                    List <int> list1  = Utilitys.RandomList(amount);
                    List <int> list2  = Utilitys.RandomList(amount);
                    List <int> list3  = Utilitys.RandomList(amount);
                    List <int> list4  = Utilitys.RandomList(amount);

                    Console.WriteLine("--------");
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine("Amount: " + amount);
                    Console.ResetColor();

                    watch = Stopwatch.StartNew();
                    List <int> bubbelList = BubbelSort(list1);
                    watch.Stop();
                    Utilitys.WriteOutTime(watch, "BubbelSort");

                    watch = Stopwatch.StartNew();
                    List <int> insertionList = InsertionSort(list2);
                    watch.Stop();
                    Utilitys.WriteOutTime(watch, "InsertionSort");

                    watch = Stopwatch.StartNew();
                    List <int> mergeList = MergeSort(list3);
                    watch.Stop();
                    Utilitys.WriteOutTime(watch, "MergeSort");

                    watch = Stopwatch.StartNew();
                    List <int> quickList = Quick_Sort_Start(list4);
                    watch.Stop();
                    Utilitys.WriteOutTime(watch, "QuickSort");
                }

                for (int i = 5; i <= 8; i++)                 // om i går över 10 kommer typ 100GB utav ram
                {
                    if (i >= 9)
                    {
                        System.Environment.Exit(0);
                    }
                    else if (sortor > 15)
                    {
                        i = 9;
                    }
                    int bigAmount = Convert.ToInt32(Math.Pow(10, i));
                    Console.WriteLine("--------");
                    Console.WriteLine("Amount: " + bigAmount);
                    //List<int> list5 = Utilitys.RandomList(bigAmount);
                    List <int> list6 = Utilitys.RandomList(bigAmount);

                    /*
                     * watch = Stopwatch.StartNew();
                     * List<int> mergeList2 = MergeSort(list5);
                     * watch.Stop();
                     * Utilitys.WriteOutTime(watch, "MergeSort");
                     */

                    watch = Stopwatch.StartNew();
                    //List<int> quickList2 = Quick_Sort_Start(list6);
                    list6.Sort();
                    watch.Stop();
                    Utilitys.WriteOutTime(watch, "QuickSort");
                }
            }
            else
            {
                System.Environment.Exit(99);
            }
        }