private static int[] heapSort(final int[] data) {

        /**
         * Populate sorted data structure "Heap" (i.e. TreeSet in Java) with
         * all the input data.
         **/
        final TreeSet<Integer> heap
            = new TreeSet<Integer>(new IntegerComparator());
        for (int i = 0; i < data.length; i++) {
            heap.add(data[i]);
            mIterations++;
        }

        /**
         * Copy the data from the "Heap" back into an array.
         **/
        final int[] result = new int[data.length];
        for (int i = 0; i < data.length; i++) {
            result[i] = heap.pollFirst();
            mIterations++;
        }

        return result;
    }