This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes problems with mergeSort, help please Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "problems with mergeSort, help please" Watch "problems with mergeSort, help please" New topic
Author

problems with mergeSort, help please

Yotam Ohayon
Greenhorn

Joined: Dec 31, 2010
Posts: 26
hi, i've written a little version of merge sort. it's a little different then what i've seen but should work the same. for some reason, if the array i'm trying to sort has more then 4 values it just replaces the right half with the left half (work fine up to 4 values, weird). i've checked my merge() method several times and it's okay, and i tried debugging my sort method more then once but cuoldn't figure out my error. could it has something to do with the fact that i've used static methods?
anyway, here's the code i've written:
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19232

sort doesn't modify its arguments. Therefore, at the bottom of the sort method, you ignore the actual results from the two calls to sort. I've got your code working by changing those two lines:


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Yotam Ohayon
Greenhorn

Joined: Dec 31, 2010
Posts: 26
hm
i feel stupid. thatnk you!
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19232

You're welcome.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: problems with mergeSort, help please
 
Similar Threads
stuck in a loop
Help with using mergesort to sort a list of names alphabetically?
Multidimensional Arrays problem
Overwriting an array.
recursive problem