예제 #1
0
        private static void TestHeapIntWithComparator()
        {
            var comper = new Comper();
            var heap   = new BinaryHeap <int>(comper);

            heap.Add(4);
            heap.Add(7);
            heap.Add(1);
            heap.Add(777);
            heap.Add(12);
            heap.Add(3);
            heap.RemoveTop();
            Console.WriteLine(heap.GetTopElement());
        }
예제 #2
0
        private static void TestHeap1()
        {
            var heap = new BinaryHeap <int>();

            heap.Add(4);
            heap.Add(7);
            heap.Add(1);
            heap.Add(777);
            heap.Add(12);
            heap.Add(3);
            heap.RemoveTop();
            heap.RemoveTop();
            Console.WriteLine(heap.GetTopElement());
        }
예제 #3
0
        public static void Main(string[] args)
        {
            BinaryHeap <int> priorityQueue = new BinaryHeap <int>();

            priorityQueue.Add(4);
            priorityQueue.Add(6);
            priorityQueue.Add(9);
            priorityQueue.Add(22);
            priorityQueue.Add(5);
            priorityQueue.Add(3);
            priorityQueue.Add(13);
            priorityQueue.Add(37);
            priorityQueue.Add(100);
            priorityQueue.Add(46);

            while (priorityQueue.Count > 0)
            {
                Console.WriteLine(priorityQueue.Remove());
            }
        }
예제 #4
0
 /// <summary>
 /// Constructor using predefined priority rules
 /// </summary>
 /// <param name="compararer">The compararer which will set the priority rules</param>
 public PriorityQueue(Comparer <T> compararer)
 {
     this.queue = new BinaryHeap <T>(compararer);
 }
예제 #5
0
 public PriorityQueue() : this(Comparer <T> .Default)
 {
     data = new BinaryHeap <T>(this.Comparer);
 }
예제 #6
0
 public PriorityQueue()
 {
     this.data = new BinaryHeap <T>();
 }
예제 #7
0
 public PriorityQueue(Comparison <T> comparison)
 {
     this.data = new BinaryHeap <T>(4, comparison);
 }