List of usage examples for java.util PriorityQueue add
public boolean add(E e)
From source file:Main.java
public static void main(String args[]) { PriorityQueue<Integer> prq = new PriorityQueue<Integer>(); for (int i = 0; i < 10; i++) { prq.add(i); }/* w w w .j a v a2 s . com*/ // create iterator from the queue Iterator it = prq.iterator(); while (it.hasNext()) { System.out.println("Value: " + it.next()); } }
From source file:Main.java
public static void main(String args[]) { PriorityQueue<Integer> prq = new PriorityQueue<Integer>(); // insert values in the queue prq.add(1); prq.add(2);/*from w w w .ja va 2 s .com*/ prq.add(3); prq.add(6); prq.add(5); System.out.println(prq); // create comparator Comparator comp = prq.comparator(); System.out.println("Comparator value is: " + comp); }
From source file:Main.java
public static void main(String args[]) { PriorityQueue<Integer> prq = new PriorityQueue<Integer>(); for (int i = 3; i < 10; i++) { prq.add(i); }/* w ww . ja v a 2 s .c o m*/ System.out.println(prq); // get the head from the queue Integer head = prq.poll(); System.out.println("Head of the queue is: " + head); System.out.println(prq); }
From source file:Main.java
public static void main(String args[]) { PriorityQueue<Integer> prq = new PriorityQueue<Integer>(); // insert values in the queue prq.add(6); prq.add(9);/* w w w. ja v a 2 s .co m*/ prq.add(5); prq.add(64); prq.add(6); System.out.println(prq); // get objects from the queue Object[] arr = prq.toArray(); for (int i = 0; i < arr.length; i++) { System.out.println(arr[i]); } }
From source file:Main.java
public static void main(String... args) { PriorityQueue<Flight> flights = new PriorityQueue<Flight>(5, new SortQueueViaPriority()); flights.add(new Flight("0001", 9)); flights.add(new Flight("0002", 7)); flights.add(new Flight("0003", 1)); flights.add(new Flight("0004", 2)); flights.add(new Flight("0005", 1)); while (!flights.isEmpty()) System.out.println(flights.remove()); }
From source file:Main.java
public static void main(String args[]) { PriorityQueue<Integer> prq = new PriorityQueue<Integer>(10, Collections.reverseOrder()); for (int i = 0; i < 10; i++) { prq.add(i); }/*from w w w. j a v a 2 s. c o m*/ System.out.println(prq); }
From source file:Main.java
public static void main(String args[]) { PriorityQueue<Integer> prq = new PriorityQueue<Integer>(); // insert values in the queue prq.add(1); prq.add(2);/* w w w.j a va 2 s . co m*/ prq.add(1); prq.add(64); prq.add(1); System.out.println(prq); // create arr1 Integer[] arr1 = new Integer[5]; // use toArrsy() method Integer[] arr2 = prq.toArray(arr1); for (int i = 0; i < arr1.length; i++) { System.out.println(arr1[i]); } for (int i = 0; i < arr2.length; i++) { System.out.println(arr2[i]); } }
From source file:Main.java
public static void main(String args[]) { PriorityQueue<Integer> prq = new PriorityQueue<Integer>(10, Collections.reverseOrder()); for (int i = 0; i < 10; i++) { prq.add(i); }// w w w . ja va 2 s. c om PriorityQueue<Integer> p = new PriorityQueue<Integer>(prq); System.out.println(prq); }
From source file:Main.java
public static void main(String args[]) { PriorityQueue<Integer> prq = new PriorityQueue<Integer>(); // insert values in the queue for (int i = 3; i < 10; i++) { prq.add(i); }//from www. jav a 2 s . c om System.out.println(prq); // remove 7 from the queue boolean isremoved = prq.remove(7); System.out.println("Return value after remove: " + isremoved); System.out.println(prq); }
From source file:SequentialPageRank.java
@SuppressWarnings({ "static-access" }) public static void main(String[] args) throws IOException { Options options = new Options(); options.addOption(OptionBuilder.withArgName("path").hasArg().withDescription("input path").create(INPUT)); options.addOption(/*from w w w . j a v a2 s.c o m*/ OptionBuilder.withArgName("val").hasArg().withDescription("random jump factor").create(JUMP)); CommandLine cmdline = null; CommandLineParser parser = new GnuParser(); try { cmdline = parser.parse(options, args); } catch (ParseException exp) { System.err.println("Error parsing command line: " + exp.getMessage()); System.exit(-1); } if (!cmdline.hasOption(INPUT)) { System.out.println("args: " + Arrays.toString(args)); HelpFormatter formatter = new HelpFormatter(); formatter.setWidth(120); formatter.printHelp(SequentialPageRank.class.getName(), options); ToolRunner.printGenericCommandUsage(System.out); System.exit(-1); } String infile = cmdline.getOptionValue(INPUT); float alpha = cmdline.hasOption(JUMP) ? Float.parseFloat(cmdline.getOptionValue(JUMP)) : 0.15f; int edgeCnt = 0; DirectedSparseGraph<String, Integer> graph = new DirectedSparseGraph<String, Integer>(); BufferedReader data = new BufferedReader(new InputStreamReader(new FileInputStream(infile))); String line; while ((line = data.readLine()) != null) { line.trim(); String[] arr = line.split("\\t"); for (int i = 1; i < arr.length; i++) { graph.addEdge(new Integer(edgeCnt++), arr[0], arr[i]); } } data.close(); WeakComponentClusterer<String, Integer> clusterer = new WeakComponentClusterer<String, Integer>(); Set<Set<String>> components = clusterer.transform(graph); int numComponents = components.size(); System.out.println("Number of components: " + numComponents); System.out.println("Number of edges: " + graph.getEdgeCount()); System.out.println("Number of nodes: " + graph.getVertexCount()); System.out.println("Random jump factor: " + alpha); // Compute PageRank. PageRank<String, Integer> ranker = new PageRank<String, Integer>(graph, alpha); ranker.evaluate(); // Use priority queue to sort vertices by PageRank values. PriorityQueue<Ranking<String>> q = new PriorityQueue<Ranking<String>>(); int i = 0; for (String pmid : graph.getVertices()) { q.add(new Ranking<String>(i++, ranker.getVertexScore(pmid), pmid)); } // Print PageRank values. System.out.println("\nPageRank of nodes, in descending order:"); Ranking<String> r = null; while ((r = q.poll()) != null) { System.out.println(r.rankScore + "\t" + r.getRanked()); } }