@@ -0,0 +1,1098 @@
+package org.psjava.example;%0D%0A%0D%0Aimport org.junit.Assert;%0D%0Aimport org.junit.Test;%0D%0Aimport org.psjava.ds.heap.BinaryHeapFactory;%0D%0Aimport org.psjava.ds.heap.Heap;%0D%0Aimport org.psjava.ds.heap.HeapNode;%0D%0Aimport org.psjava.javautil.DefaultComparator;%0D%0A%0D%0Apublic class HeapExample %7B%0D%0A%0D%0A%09@Test%0D%0A%09public void example() %7B%0D%0A%0D%0A%09%09// Let's create a small heap.%0D%0A%0D%0A%09%09Heap%3CInteger%3E heap = new BinaryHeapFactory().create(new DefaultComparator%3CInteger%3E());%0D%0A%09%09heap.insert(100);%0D%0A%09%09heap.insert(300);%0D%0A%09%09heap.insert(200);%0D%0A%0D%0A%0D%0A%09%09// This is most basic operation. Extract minimum.%0D%0A%0D%0A%09%09int extracted = heap.extractMinimum();%0D%0A%09%09Assert.assertEquals(100, extracted);%0D%0A%0D%0A%0D%0A%09%09// You can only get the miminum without extraction.%0D%0A%0D%0A%09%09int minimum1 = heap.getMinimum();%0D%0A%09%09Assert.assertEquals(200, minimum1);%0D%0A%0D%0A%0D%0A%09%09// Let's do decrease-key operation.%0D%0A%09%09// Get the node as like a pointer when you insert, and decreasing is%0D%0A%09%09// done by the node.%0D%0A%0D%0A%09%09HeapNode%3CInteger%3E node = heap.insert(400);%0D%0A%09%09node.decreaseKey(10); // decrease 400 -%3E 10%0D%0A%0D%0A%09%09int minimum2 = heap.getMinimum();%0D%0A%09%09Assert.assertEquals(10, minimum2);%0D%0A%09%7D%0D%0A%0D%0A%7D%0D%0A

add heap example