Solved

Sorting an array of doubles

Posted on 1998-09-03
6
223 Views
Last Modified: 2011-04-14
I'm confronting the problem to sort an array that contains atomic doubles not the objects Double. My question now is whether it is possible to do that in Java using the quicksort algorithm. My trials failed. Probably, since it is not possible to pass an array like a pointer like one can do in C/C++. I don't like to wrap all doubles into Double object because of perfomance lack. The I had to wrap all doubles into Doubles and after the sorting I had to unwrap the sorted Objects into the old array. Another possibility was to use a native call but I think this would be too clumsy. Any help will be appreciated.
0
Comment
Question by:trouvain
  • 2
  • 2
6 Comments
 
LVL 8

Accepted Solution

by:
diakov earned 200 total points
ID: 1223430
I think that the internal types in Java are internal mainly because of performance considerations. So why not swap double values? I believe you can make a benchmark and see whether it is relevant. (I mean wrapping and unwrapping versus double values).
If you're so relluctant to swap dowbles, you can also use an array of int indices pointing in the array of doubles. This way you swap int's which is the same as swaping pointers in C. At the end you need only one pass with O(N) to get them ordered from the array.

Cheers.
0
 
LVL 5

Expert Comment

by:fontaine
ID: 1223431
You should have a look at the Java Generic collection Library (JGL) http://www.objectspace.com/jgl/. It contains all kind of ready to use algorithms, carefully
designed to be efficient.
0
 

Author Comment

by:trouvain
ID: 1223432
I'm not reluctant to swap doubles how else should I sort an array? I overworked the quicksort algorithm and found the mistake. I only was mischieved by the idea that swapping values in an array doesn't work in Java because of the referencing approach.

0
 

Author Comment

by:trouvain
ID: 1223433
Dear fontaine,

thank you for giving the link to objectspace, it was much more helpful than the given answer!
0
 
LVL 8

Expert Comment

by:diakov
ID: 1223434
Tell me how to return the points, please.
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question