public static int choosePivot(int offset, int len, int type) {
		int pivot;

		switch (type) {
		
		//choose the first element
		case 0:
			pivot = offset;
			break;

		//choose the last element
		case 1:
			pivot = offset + len - 1;
			break;
			
		//choose the median
		case 2:
			if (len < 3){
				pivot = offset;
				break;
			}
			
			int mid = offset + len/2 - 1 + len % 2;
			int last = offset+len-1;
			
			if(data.get(mid) > data.get(offset)){
				if(data.get(last) > data.get(mid))
					pivot = mid;
				else if(data.get(last) > data.get(offset))
					pivot = last;
				else
					pivot = offset;
			} else {
				if(data.get(last) > data.get(offset))
					pivot = offset;
				else if(data.get(last) > data.get(mid))
					pivot = last;
				else
					pivot = mid;
			}			
			break;
						
		default:
			pivot = offset;

		}

		return pivot;
	}