Exemple #1
0
 public static void GenerateReversed(SortingArray array)
 {
     for (int i = 0; i < array.Length; i++)
     {
         array.Modify(i, array.Length - i);
         Updated(array);
     }
 }
Exemple #2
0
 public static void GenerateRandom(SortingArray array)
 {
     for (int i = 0; i < array.Length; i++)
     {
         StandardGenerator rand = new StandardGenerator();
         int val = rand.Next(1, array.Length + 1);
         array.Modify(i, val);
         Updated(array);
     }
 }
Exemple #3
0
 public static void GenerateRandomAscending(SortingArray array)
 {
     for (int i = 0; i < array.Length; i++)
     {
         StandardGenerator rand = new StandardGenerator();
         int value = rand.Next(i, array.Length) + 1;
         array.Modify(i, value);
         Updated(array);
     }
 }
Exemple #4
0
        public static void GenerateCubic(SortingArray array)
        {
            double a = array.Length / 2;
            double n = 1 / (a * a);

            for (int x = 0; x < array.Length; x++)
            {
                double t = x - a;
                int    y = Math.Min(array.Length, (int)(n * (t * t * t) + a) + 1);
                array.Modify(x, y);
                Updated(array);
            }
            Shuffle(array);
        }
Exemple #5
0
        public static void Generate8Blocked(SortingArray array)
        {
            double d   = array.Length / 8.0;
            double val = d;

            for (int i = 0; i < array.Length; i++)
            {
                if (i >= val)
                {
                    val += d;
                }
                array.Modify(i, (int)val);
                Updated(array);
            }
            Shuffle(array);
        }
Exemple #6
0
        static void MergeSortRecursion(SortingArray array, int[] temp, int left, int right)
        {
            if (left < right)
            {
                int len = right - left + 1;
                int mid = left + len / 2;
                MergeSortRecursion(array, temp, left, mid - 1);
                MergeSortRecursion(array, temp, mid, right);

                int p1 = left;
                int p2 = mid;

                for (int i = 0; i < len; i++)
                {
                    bool first = true;

                    if ((p1 >= mid) | (p2 <= right && array.IsBigger(p1, p2)))
                    {
                        first = false;
                    }

                    if (first)
                    {
                        temp[i] = array.Get(p1);
                        p1++;
                    }
                    else
                    {
                        temp[i] = array.Get(p2);
                        p2++;
                    }
                    Updated(array);
                }

                for (int i = 0; i < len; i++)
                {
                    array.Modify(left + i, temp[i]);
                    Updated(array);
                }
            }
        }