/// <summary> /// Enqueues an element into the priority queue. /// </summary> /// <param name="the_addition">the element to enqueue.</param> /// <returns>true if the element was added successfully, otherwise false.</returns> public bool enqueue(T the_addition) { try { return(my_heap.add(the_addition)); } catch (ClassCastException the_ex) //this will be called when percolateUp() is called { throw new ClassCastException("You did not provide a comparator to the priority queue and your " + "elements are not comparable."); } }
private void testDeleteMin(BasicHeap <DSInteger> the_heap) { //removing of the default items handled in testAdd() while (!the_heap.isEmpty()) { the_heap.deleteMin(); } Assert.AreEqual(null, the_heap.deleteMin()); Assert.AreEqual(true, the_heap.isEmpty()); //adding items after all are removed, then check for correct state the_heap.add(new DSInteger(5)); Assert.AreEqual(5, the_heap.deleteMin().value); Assert.AreEqual(null, the_heap.deleteMin()); Assert.AreEqual(true, the_heap.isEmpty()); Assert.AreEqual(true, the_heap.isEmpty()); }
//---------------- HELPER METHODS ----------------- private void addHeapItems(BasicHeap <DSInteger> the_heap) { the_heap.add(new DSInteger(30)); the_heap.add(new DSInteger(100)); the_heap.add(new DSInteger(40)); the_heap.add(new DSInteger(10)); the_heap.add(new DSInteger(60)); the_heap.add(new DSInteger(70)); the_heap.add(new DSInteger(20)); the_heap.add(new DSInteger(110)); the_heap.add(new DSInteger(50)); the_heap.add(new DSInteger(5)); the_heap.add(new DSInteger(90)); the_heap.add(new DSInteger(80)); }