Solved

Sorting an array of doubles

Posted on 1998-09-03
6
224 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 Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
difference of if loops 23 62
add projects t working set in maven 2 24
printf performancy 11 73
swing controls 2 16
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

830 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