Ejemplo n.º 1
0
        public void Test_Sort_AcceptedInterfase_KeySum()
        {
            double[][] a = new double[3][];
            a[0] = new double[2] {
                2, 2
            };
            a[1] = new double[2] {
                3, 3
            };
            a[2] = new double[3] {
                1, 1, 1
            };
            IComparer <Double[]> comparer = new SumComparer();

            SortClass.Sort(a, comparer);
            CollectionAssert.AreEqual(a[0], new double[3] {
                1, 1, 1
            });
            CollectionAssert.AreEqual(a[1], new double[2] {
                2, 2
            });
            CollectionAssert.AreEqual(a[2], new double[2] {
                3, 3
            });
        }
Ejemplo n.º 2
0
 static void Main(string[] args)
 {
     string[] array = new string[] { "we're calling", "for", "freedom", "aaaaaaaaaaaaaaaaaaaaaaaa", "fantasy_is_about_to_end" };
     SortClass.Sort(array, Compare);
     foreach (var item in array)
     {
         Console.WriteLine(item);
     }
 }
Ejemplo n.º 3
0
        public void test()
        {
            Stopwatch timePerParse;
            var       numbers       = 16;
            long      ticksThisTime = 0;

            int[] datata = new int[numbers];
            for (int i = 0; i < numbers; i++)
            {
                Random random = new Random();
                var    number = random.Next(0, 10000);
                datata[i] = number;
            }
            var data2 = new int[datata.Length];
            var data3 = new int[datata.Length];
            var data4 = new int[datata.Length];
            var data5 = new int[datata.Length];

            datata.CopyTo(data2, 0);
            datata.CopyTo(data3, 0);
            datata.CopyTo(data4, 0);
            datata.CopyTo(data5, 0);

            timePerParse = Stopwatch.StartNew();
            SortClass.Sort(ref datata);
            timePerParse.Stop();
            ticksThisTime = timePerParse.ElapsedTicks;
            Console.WriteLine("MainSort     " + ticksThisTime);


            timePerParse = Stopwatch.StartNew();
            SortClass.QuickSort(ref data2, data2[0], data2.Length - 1);
            timePerParse.Stop();
            ticksThisTime = timePerParse.ElapsedTicks;
            Console.WriteLine("QuickSort     " + ticksThisTime);


            timePerParse = Stopwatch.StartNew();
            SortClass.InsertionSort(ref data4);
            timePerParse.Stop();
            ticksThisTime = timePerParse.ElapsedTicks;
            Console.WriteLine("InsertionSort     " + ticksThisTime);

            timePerParse = Stopwatch.StartNew();
            SortClass.HeapSort(ref data5);
            timePerParse.Stop();
            ticksThisTime = timePerParse.ElapsedTicks;
            Console.WriteLine("HeapSort      " + ticksThisTime);
        }
Ejemplo n.º 4
0
 //Method call QuickSort
 private static void Sort(object o)
 {
     if (o is ArrayAndComparer <T> )
     {
         //Cast object and appeal to array
         ArrayAndComparer <T> args = o as ArrayAndComparer <T>;
         SortClass.Sort <T>(args.Array, args.Compare);
         //Notificaton that sorting is complete
         OnSorting?.Invoke(args.Array);
         OnSorting -= OnSortingArrayHandler <T>;
     }
     else
     {
         throw new InvalidCastException("Object is not array and comparer");
     }
 }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            var numberList = new List <int>
            {
                5,
                7,
                1,
                2,
                3,
                99
            };

            var sort   = new SortClass(new SortAsc(), numberList);
            var result = sort.Sort();

            foreach (var item in result)
            {
                Console.WriteLine(item);
            }

            Console.ReadKey();
        }
Ejemplo n.º 6
0
 public void Test_Sort_AcceptedDelegate_KeySum()
 {
     double[][] a = new double[3][];
     a[0] = new double[2] {
         2, 2
     };
     a[1] = new double[2] {
         3, 3
     };
     a[2] = new double[3] {
         1, 1, 1
     };
     SortClass.Sort(a, KeySum);
     CollectionAssert.AreEqual(a[0], new double[3] {
         1, 1, 1
     });
     CollectionAssert.AreEqual(a[1], new double[2] {
         2, 2
     });
     CollectionAssert.AreEqual(a[2], new double[2] {
         3, 3
     });
 }