// Arup Guha
// 1/28/2017
// Example to show the basic use of an PriorityQueue in Java

import java.util.*;

public class usepq {

	public static void main(String[] args) {

		Random r = new Random();

		// Just of integers, but we can do a PriorityQueue of any class that implements Comparable.
		PriorityQueue<Integer> myPQ = new PriorityQueue<Integer>();

		// Do 50 random operations.
		for (int loop=0; loop<50; loop++) {

			// Add if there's nothing in the queue.
			if (myPQ.size() == 0) {
				int add = r.nextInt(100);
				myPQ.offer(add);
				System.out.println("Just added "+add);
			}
			
			// Here we add 1/2 the time and remove the other half the time.
			else {
				
				int option = r.nextInt(2);
				
				// Add something.
				if (option == 0) {
					int add = r.nextInt(100);
					myPQ.offer(add);
					System.out.println("Added "+add);
				}
				
				// Remove the lowest, what a priority queue naturally does in O(lg n) time.
				else {
					int item = myPQ.poll();
					System.out.println("Just removed "+item);
				}
			}

		}
	}
}