This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes Merge Sort Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Merge Sort" Watch "Merge Sort" New topic

Merge Sort

sylvia greene
Ranch Hand

Joined: Jun 23, 2004
Posts: 40
I am trying to implement the merge sort algo.
I have written the following code

I have a slight problem here. If I take the number of elements in "b" array more than number of elements in "a" array, I get a ArrayIndexOutOfBoundsException.I works when both "a" and "b" have same number of elements and when "a" has more elemetnts than "b".
Please help me resolve this .
Kalai Selvan
Ranch Hand

Joined: Jul 07, 2004
Posts: 79
Hi sylvia,

I am not too sure about your logic. But I found two solution for the problem....

I hope this will work....

Kalai S.
I agree. Here's the link:
subject: Merge Sort
Similar Threads
Question about finding common integer from two integer array
Intersection of two arrays
Sorting Asciibetically
Help me with matrix...please!!!!!!!
Finding Nth Largest element of an array without sorting