void heapify( heap q, double[] HeapArray, int i, int n )
	{
		boolean moreswap = true;
		do 
		{
			int left = 2 * i;
			int right = 2* i + 1;
			int smallest;
			if ((left <= n) &&	(HeapArray[p[left]] < HeapArray[p[i]]))
				smallest = left;
			else
				smallest = i;
			if ((right <= n) && (HeapArray[p[right]] < HeapArray[p[smallest]]))
				smallest = right;
			if (smallest != i)
			{
				swap(q,i, smallest);     
				// push smallest up the heap
				i = smallest; //check next level down
			}
			else
				moreswap = false;
		} while (moreswap);
	}