Exemple #1
0
        public void Test2()
        {
            var input = new List <int> {
                1, 9, 8, 21, 2, 3, 5, 12, 3, 2
            };
            var solver = new PancakeSort();
            var flips  = solver.Solve(input.ToArray());

            foreach (int flip in flips)
            {
                input = input.ReverseUntil(flip);
            }

            Assert.True(input.IsSorted());
        }
Exemple #2
0
        static void Main(string[] args)
        {
            Console.WriteLine(string.Join(" ", ArrayGenerator.Generate(10, false, 1, 11)));

            Console.WriteLine();

            var array = ArrayGenerator.Generate(10, true, 1, 151);

            Console.WriteLine(string.Join(" ", array));

            var result = new int[0];
            var ticks  = 0L;

            array = new[] { 5, 4, 3, 2, 1, 6, 6, 7, 2, 8, 9, 3 };

//            var time = PerformanceAnalyzer.GetExecutionTime(() => result = new Bogosort<int>().SortDebug(array, ListSortDirection.Ascending, out ticks));

//            Console.WriteLine($"Random sort:\n{string.Join(" ", result)} for {time.Milliseconds} ms; {ticks} iterations");

//            var time = PerformanceAnalyzer.GetExecutionTime(() => result = new BruteForceSort<int>().SortDebug(array, ListSortDirection.Ascending, out ticks));

//            Console.WriteLine($"Brute force sort:\n{string.Join(" ", result)} for {time.Milliseconds} ms; {ticks} iterations");

            var time = PerformanceAnalyzer.GetExecutionTime(() => result = new PancakeSort <int>().Sort(array, ListSortDirection.Ascending));

            Console.WriteLine($"Brute force sort:\n{string.Join(" ", result)} for {time.Milliseconds} ms; {ticks} iterations");

            /*var busted = new int[array.Length];
             *
             * var count = 0;
             *
             * Bust(busted, array, 0, ref count);*/

//            Console.WriteLine($"Total combinations: {count}");

/*              array.Shuffle();
 *          Console.WriteLine(string.Join(" ", array));
 *
 *          array.Shuffle(1);
 *          Console.WriteLine(string.Join(" ", array));*/

            Console.ReadLine();
        }
 public void PancakeSetUp()
 {
     Sorter = new PancakeSort();
 }