CSC220 Lab 7
Due: 10:59AM, Tuesday, November 16
Your task is to write a code for an enhanced priority queue,
based on the partial code provded.
Download KWOPriorityQueue.java.
This is a priority queue implmented using a binary heap.
Some methods are missing in the code:
- public void swap(int a, int b)
This is a method for swapping the data at position a and the data at
position b.
- public int size()
This is a method for obtaining the total number of elements stored
in the queue.
- public Iterator iterator()
This is a method for obtaining an iterator of the data in the
increasing order with respect to the comparator. This can be
implmented by a mehtod that
-
creates a copy of the queue,
-
executes repeated removal on the copy to build an ordered list
of the data objects as a LinkedList, and then
-
returns an iterator of the LinkedList thus created.
- public E peek()
As required by the Queue interface,
this is a method for obtaining the top element without having
to remove it from the queue.
- public KWOPriorityQueue copy()
This is a method for obtaining a copy of queue, without copying
each data object E.
- public boolean modify(int a, E o)
This is a method for substituting the element at location a with
object o and then re-heap. Depending on the relationship between
the data currently stored at location a and the new data o, which
of the two possible conflict resolutions should be determined.
We want to test the correctness of the above queue class using
a class for storing a word and a number.
WordCountInt.java is an interface
written for storing such pair of data. Implement this interface
to write a class WordCount.java. Write a program that tests the queue
using WordCount as the class to be stored. You don't have to develop
a Comparator of WordCount, KWOPriorityQueue will default to the compareTo
method as required in WordCountInt.java.