Solved

Sorting an array of doubles

Posted on 1998-09-03
6
221 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now