Пример #1
0
        /// <summary>
        /// Use the build heap algorithm to sort the array.
        /// </summary>
        static void SortAllBuildHeap(MyStopwatch thestopwatch, int arrsize)
        {
            int[] arr = new int[arrsize];
            for (int i = 0; i < arr.Length; arr[i] = i + 1, i++)
            {
                ;
            }
            Randomize(arr);
            thestopwatch.Tick();
            IPriorityQ <int> q = MyLittleArrayHeapPriorityQueue <int> .BuildHeap(arr);

            for (int i = 0; i < arr.Length; i++)
            {
                int themin = q.RemoveMin();
                if (themin != i + 1)
                {
                    throw new Exception($"Expected: {i + 1} but {themin}");
                }
            }
            thestopwatch.Tock();
        }
Пример #2
0
 public void BinaryHeapBasic(
     int size,
     int repetition,
     PriorityQImplementations type = PriorityQImplementations.SimpleBinaryHeap
     )
 {
     for (int j = 1; j <= repetition; j++)
     {
         IPriorityQ <int> q         = GetInstance <int>(type);
         int[]            randomarr = GetRandomizedIntSequence(size);
         for (int i = 0; i < randomarr.Length; q.Enqueue(randomarr[i]), i++)
         {
             ;
         }
         for (int i = 0;
              i < randomarr.Length;
              Assert.AreEqual(i + 1, q.RemoveMin()), i++)
         {
             ;
         }
     }
 }