private int stablePartition(int[] array, int[] temp, int lowindex, int highindex, boolean reversed) {
		Compare firstcond, secondcond;
		if (reversed){
			firstcond = new Compare(Compare.type.GREATERTHAN);
			secondcond = new Compare(Compare.type.LESSTHAN);
		}
		else{
			firstcond = new Compare(Compare.type.LESSTHAN);
			secondcond =  new Compare(Compare.type.GREATERTHAN);
		}
		int pivot = 0;
		int midindex = (lowindex + highindex) /2;
		int median = getmedian(lowindex, highindex, midindex, 
				array[lowindex], array[highindex], array[midindex]);

		int index = lowindex;
		for(int i = lowindex; i <= highindex; i++){
			if (firstcond.compareto(array[i], array[median])){
				temp[index] = array[i];
				index++;
			}
		}

		for(int i = lowindex; i <= highindex; i++){
			if (array[i] == array[median]){
				if (median == i)
					pivot = index;
				temp[index] = array[i];
				index++;
			}
		}

		for(int i = lowindex; i <= highindex; i++){			
			if (secondcond.compareto(array[i], array[median])){
				temp[index] = array[i];
				index++;
			}
		}

		for(int i = lowindex; i <= highindex; i++)
			array[i] = temp[i];
		temp = null;
		return pivot;
	}