1. Member
Join Date
Sep 2010
Posts
3
Rep Power
0

## 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

Java 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;
}```
Last edited by desconocido; 09-15-2010 at 03:29 AM.

2. error of array out of bounds
What array, what variable, what line of code and what is the index's value.

3. Member
Join Date
Sep 2010
Posts
3
Rep Power
0
it says line 10,but thats
Java 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

4. 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]
Last edited by Norm; 09-15-2010 at 04:38 AM.

5. Member
Join Date
Sep 2010
Posts
3
Rep Power
0
i dont know witch array/variable may be
and index value is variable

6. Add some print outs to show the values of the variables.
The error message will show the index value that is out of range.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•