1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
| public static int[] NonIntersectIntArray(int[] a, int [] b)
{
DEBUG.ASSERT(a != null);
DEBUG.ASSERT(b != null);
Vector theResult = new Vector();
int[] naIdx = GetIndirectionVector(a);
int[] nbIdx = GetIndirectionVector(b);
int i=0,j=0;
int nIdx1=0;
while(true)
{
if(i!=a.length) nIdx1 = naIdx[i];
int nIdx2 = nbIdx[j];
if(i!=a.length)// if we are not at the end of a[]
{
if (a[nIdx1] < b[nIdx2])
{
i++;
}
else if (a[nIdx1] == b[nIdx2])
{
i++;
j++;
}
else if (a[nIdx1] > b[nIdx2])
{
theResult.add(new Integer(nIdx2));
j++;
}
}
else// if we are at the end of a[]
{
if (a[nIdx1] < b[nIdx2])
{
theResult.add(new Integer(nIdx2));
j++;
}
else if (a[nIdx1] == b[nIdx2])
{
j++;
}
else if (a[nIdx1] > b[nIdx2])
{
int u = nIdx1;
while(a[u]>b[nIdx2])
{
u--;
if(a[u]==b[nIdx2])
{
j++;
break;
}
else if(a[u]<b[nIdx2])
{
theResult.add(new Integer(nIdx2));
j++;
break;
}
}
}
}
if ( j == b.length)// in all the case it's finish
break;
}
return IntVectorToIntArray(theResult);
} |