Example #1
0
 private static int TestMaxify(int[] array, int seed, SinkMethod sinkMethod, int repetitionIndex, ref long comparisonsSum, ref long swapsSum)
 {
     InitializeArray(array, seed);
     if (repetitionIndex == 0)
     {
         Dump(array);
     }
     Heaps.Maxify(array, sinkMethod);
     if (repetitionIndex == 0)
     {
         Dump(array);
         Console.WriteLine($"Maximum: {Heaps.maximum} Seed: {seed} Swaps: {Heaps.swaps} Comparisons: {Heaps.comparisons}", new object[0]);
     }
     comparisonsSum += Heaps.comparisons;
     swapsSum       += Heaps.swaps;
     return(Heaps.maximum);
 }
Example #2
0
        private static int TestSink(int[] array, int seed, SinkMethod sinkMethod, int repetitionIndex, ref long comparisonsSum, ref long swapsSum)
        {
            int value = new Random(seed * 2).Next(array.Length);

            array[0] = value;
            if (repetitionIndex == 0)
            {
                Dump(array);
            }
            Heaps.Sink(array, sinkMethod);
            if (repetitionIndex == 0)
            {
                Dump(array);
                Console.WriteLine($"Maximum: {Heaps.maximum} Seed: {seed} Swaps: {Heaps.swaps} Comparisons: {Heaps.comparisons}", new object[0]);
            }
            comparisonsSum += Heaps.comparisons;
            swapsSum       += Heaps.swaps;
            return(Heaps.maximum);
        }
Example #3
0
        public static void MainRun(string[] cmdArgs)
        {
            Heaps heapCol = new Heaps(7);

            heapCol.items = new ArrayList {
                2, 3, 1, 4, 5, 7, 8
            };

            Console.WriteLine("{0},{1},{2}", heapCol.GetLeftChildValue(2), heapCol.GetRightChildValue(1), heapCol.GeParentValue(6));

            Console.WriteLine("{0},{1},{2}", heapCol.HasLeftChild(3), heapCol.HasRightChild(2), heapCol.HasParent(1));

            heapCol.Swap(3, 4);

            Console.WriteLine("Modified array list:");
            foreach (var value in heapCol.items)
            {
                Console.Write("{0} ", Convert.ToInt32(value));
            }
        }