Results 1 to 6 of 6
Thread: help with mergesort
- 09-15-2010, 02:23 AM #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
please help!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 02:29 AM.
- 09-15-2010, 02:46 AM #2
What array, what variable, what line of code and what is the index's value.error of array out of bounds
- 09-15-2010, 03:30 AM #3
Member
- Join Date
- Sep 2010
- Posts
- 3
- Rep Power
- 0
it says line 10,but thats
thats why i was thinking if there is other case i didnt writeJava Code:if((b[i]<=c[j] && i !=b.length && j !=c.length) || (i !=b.length && j ==c.length)){
- 09-15-2010, 03:35 AM #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 03:38 AM.
- 09-15-2010, 03:49 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
- 09-15-2010, 03:56 AM #6
Similar Threads
-
mergeSort
By Blue_beaver in forum New To JavaReplies: 2Last Post: 10-11-2009, 10:55 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks