Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Sorting an array of doubles

Posted on 1998-09-03
6
Medium Priority
?
234 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 400 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

Technology Partners: 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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

604 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