Java Reference
In-Depth Information
For example, if
q
is a priority queue defined to take
strings
:
q.add("X", 10);
q.add("Y", 1);
q.add("Z", 3);
System.out.println(q.remove());
// Returns X
System.out.println(q.remove());
// Returns Z
System.out.println(q.remove());
// Returns Y
Test your queue on data with priorities in various orders (e.g., ascending,
descending, mixed). You can implement the priority queue by performing a
linear search through the
ArrayList
. In future courses you may study a data
structure called a heap that is a more efficient way to implement a priority queue.