import java.io.*; import java.util.*; class HeapApp { public static void main(String[] args) throws IOException { int value, value2, identity; VertexHeap theHeap = new VertexHeap(31); // make a Heap; max size 31 boolean success; theHeap.insert(new Node(70, 0, 0)); // insert 10 items theHeap.insert(new Node(40, 1, 0)); theHeap.insert(new Node(50, 2, 0)); theHeap.insert(new Node(20, 3, 0)); theHeap.insert(new Node(60, 4, 0)); theHeap.insert(new Node(100, 5, 0)); theHeap.insert(new Node(80, 6, 0)); theHeap.insert(new Node(30, 7, 0)); theHeap.insert(new Node(10, 8, 0 )); theHeap.insert(new Node(90, 9, 0)); while(true) // until [Ctrl]-[C] { System.out.print("Enter first letter of "); System.out.print("show, insert, delete, change: "); int choice = getChar(); switch(choice) { case 's': // show theHeap.displayHeap(); theHeap.printMap(); break; case 'i': // insert System.out.print("Enter priority of node: "); value = getInt(); System.out.print("Enter identity of node: "); identity = getInt(); success = theHeap.insert(new Node(value, identity, 0)); if( !success ) System.out.println("Can't insert; heap full"); break; case 'd': // remove if( !theHeap.isEmpty() ) theHeap.delete(); else System.out.println("Can't delete; heap empty"); break; case 'c': // change System.out.print("Enter current index of item: "); value = getInt(); System.out.print("Enter new key: "); value2 = getInt(); success = theHeap.change(value, value2, 0); if( !success ) System.out.println("Invalid index"); break; default: System.out.println("Invalid entry\n"); } // end switch } // end while } // end main() //------------------------------------------------------------- public static String getString() throws IOException { InputStreamReader isr = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(isr); String s = br.readLine(); return s; } //------------------------------------------------------------- public static char getChar() throws IOException { String s = getString(); return s.charAt(0); } //------------------------------------------------------------- public static int getInt() throws IOException { String s = getString(); return Integer.parseInt(s); } //------------------------------------------------------------- } // end class HeapApp ////////////////////////////////////////////////////////////////