Solved

Sorting an array of doubles

Posted on 1998-09-03
6
229 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
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.

696 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