/* * @topic T02605 Java Generics demo * @brief Uses GenericQueue, PriorityQueTree, PriorityQueHash */ package demo; public class Main { public static void main(String[] args) { // Demo using GenericQueue based on LinkedList: GenericQueue<String> genQ = new GenericQueue<String>(); genQ.push("one"); genQ.push("two"); genQ.push("three"); genQ.push("four"); genQ.push("five"); System.out.println("GenericQueue demo:"); while (genQ.size() > 0) { String item = genQ.pull(); System.out.println(item); } System.out.println(); // Demo using TreeMap-based priority queue: System.out.println("PriorityQueTree demo:"); PriorityQueTree<String> treeQ = new PriorityQueTree<String>(); treeQ.push(3, "three"); treeQ.push(2, "two"); treeQ.push(22, "twenty two"); treeQ.push(-3, "- three"); treeQ.push(-2, "- two"); treeQ.push(-22, "- twenty two"); while (treeQ.size() > 0) { String item = treeQ.pull(); System.out.println(item); } System.out.println(); // Demo using HashMap-based priority queue // *** MAY OR MAY NOT YIELD CORRECT RESULTS ! *** System.out.println("PriorityQueHash demo:"); PriorityQueHash<String> hashQ = new PriorityQueHash<String>(); hashQ.push( 3, "three" ); hashQ.push( 2, "two" ); hashQ.push( 22, "twenty two" ); hashQ.push( -3, "- three" ); hashQ.push( -2, "- two" ); hashQ.push( -22, "- twenty two" ); while( hashQ.size() > 0 ) { String item = hashQ.pull(); System.out.println( item ); } System.out.println(); }//main }//class Main