public static void maxHeapifyTernary(TernaryHeap A, int i) {
        int l = leftTernary(i);
        int r = rightTernary(i);
        int m = middleTernary(i);
        int largest;
        if (l <= A.getHeapsize() - 1 && A.get(l) > A.get(i)) {
            largest = l;
        } else if (m <= A.getHeapsize() - 1 && A.get(m) > A.get(i)) {
            largest = m;
        } else {
            largest = i;
        }
        if (r <= A.getHeapsize() - 1 && A.get(r) > A.get(largest)) {
            largest = r;
        }
        if (largest != i) {
            A.swap(i, largest);
            maxHeapifyTernary(A, largest);
        }
    }