# help with mergesort

• 09-15-2010, 03:23 AM
desconocido
help with mergesort
hi,
im trying to do a mergesort algorithm with random numbers
i know i need to divide the array into other 2 until i got ordered arrays(or 1 and 0 length arrays) that part works great
but when i try to order (with a length of 2 or more) theres almost always an error of array out of bounds, maybe i forgot something?
heres my meth

Code:

```public static int[] order(int b[], int c[]){                 int a[]=new int[(b.length)+(c.length)];                 int i=0;                 int j=0;                 for(int k=0;k<((b.length)+(c.length));k++){                         if((b[i]<=c[j] && i !=b.length && j !=c.length) || (i !=b.length && j ==c.length)){                                 a[k]=b[i];                                 i=i+1;                         }if((b[i]>c[j] && i !=b.length && j !=c.length) || (i ==b.length && j !=c.length)){                                 a[k]=c[j];                                 j=j+1;                         }                 }                 return a;         }```
• 09-15-2010, 03:46 AM
Norm
Quote:

error of array out of bounds
What array, what variable, what line of code and what is the index's value.
• 09-15-2010, 04:30 AM
desconocido
it says line 10,but thats
Code:

`if((b[i]<=c[j] && i !=b.length && j !=c.length) || (i !=b.length && j ==c.length)){`
thats why i was thinking if there is other case i didnt write
• 09-15-2010, 04:35 AM
Norm
That's one part where are the other three:
What array, what variable, what line of code and what is the index's value.

Interesting placement of } and if. Was that intentional?

}if((b[i]>c[j]
• 09-15-2010, 04:49 AM
desconocido
i dont know witch array/variable may be
and index value is variable
• 09-15-2010, 04:56 AM
Norm
Add some print outs to show the values of the variables.
The error message will show the index value that is out of range.