private void heapify(int cur)
    {
        while (getRight(cur) < heapSize)
        {
            E left = (E)array[getLeft(cur)];
            E right = (E)array[getRight(cur)];
            if (comparator.compare(array[cur], left) > 0 ||
                comparator.compare(array[cur], right) > 0)
            {
                int min;
                if (comparator.compare(left, right) < 0)
                    min = getLeft(cur);
                else    min = getRight(cur);
                
                switchNodes(cur, min);
                cur = min;
            }
            else    return;
        }
        if (getLeft(cur) < heapSize && 
                comparator.compare(array[cur], array[getLeft(cur)]) > 0)
            switchNodes(cur, getLeft(cur));
    }