For my task, I need to find partition boundaries in sorted input. Values are expected to be repeated, I just need to find range for each value. Please check comment in following output for example. For some reason, I can not use < or > operation, I only have equality operator.
/*
Input:
Index : Value
0 : 1
1 : 1
2 : 1
3 : 2
4 : 2
5 : 2
6 : 2
Output:
Value 1 is till 2 index
Value 2 is till 6 index
*/
public void printPartitionBoundaries(ArrayList<Integer> array)
{
int f = 0;
int l = array.size()-1;
while (f < l) {
int cp = ((Integer)array.get(f)).intValue();
int of = f;
boolean done = false;
while (!done)
{
int m = (f + l)/2;
if ((l-f) <= 1) {
if ( l == array.size() -1 )
System.out.println("Value " + cp + " is till " + l + " index");
else
System.out.println("Value " + cp + " is till " + (l-1) + " index");
done = true;
break;
}
if (array.get(f).equals(array.get(l)) == false) {
if (array.get(f).equals(array.get(m)) == false)
l = m;
else
f = m;
} else {
f = m;
}
}
f = l;
l = array.size()-1;
}
}