private int sink(int i)
	{
		Key t = heap[i]; // Save key for later restoring
		while (2 * i + 1 <= N) // while heap[i] has both the children
		{
			int j = 2 * i + 1; // rightmost child

			// 1st comparision: Making j point to the least of the two
			// children as heap[i] should sink to j
			if (greater(heap[j], heap[j - 1]))
				j--;

			// 2nd comparsion. Stop sinking if heap[i] is less than its
			// least child
			if (greater(heap[j], t))
				break;

			// exch(heap, i, j);
			heap[i] = heap[j]; // half exchanges
			i = j; // Prepare 'i' for the next iteration
		}

		// if heap[i] had only one child, the comparision for sink hasn't been
		// done yet
		if (2 * i == N)
			if (greater(heap[i], heap[N]))
			{
				heap[i] = heap[N];
				i = N;
			}

		heap[i] = t; // restore
		return i;
	}