private int rotate(int i)
{
int size = heap.Length();
int j = left(i);
int k = right(i);
if (k < size && costs[k] < costs[j])
{
if (costs[k] < costs[i])
{
heapswap(k, i);
return k;
}
}
else if (j < size)
{
if (costs[j] < costs[i])
{
heapswap(j, i);
return j;
}
}
return i;
}