Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sorting algorithm

 
Gary Kit
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for reading this message...
Any1 can provide me some algorithm about the various sortings in Java ?
eg: SelectionSort, BubbleSort and bla bla... : >

cheers
 
john guthrie
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, Arrays.sort(), according to the javadoc, uses quicksort.
The JDSL (http://www.jdsl.com/) seems to implement a few others.
 
Gary Kit
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
^_^ thx.. I have another question here
is it possible to pass arrays to other methods, or classes by reference or by value ?
 
Dave Landers
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure, you can pass arrays. You can pass an array of objects or primitives, as long as the type matches the method signature (and the method knows what to do with it).
For example, some method signatures:

In that last example (bar), you can legally pass any array since all arrays are Objects.

For your second question, the answer depends on how you want to look at it.
Some say that Objects in Java are passed by reference, and primitives (int, float, etc) are passed by value.
Others like to think that everything is passed by value, because what is really happening "in the guts of the JVM", is that you are passing the object reference by value.
Passing the object reference by value is like passing the object itself by reference.
In one sense, they are both right, as they both end up with the right behavior. It just depends on how you think about things. One of them will make more sense to you and help you to remember what is happening - that's probably the one you should use.
 
Gary Kit
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thx very much~~
I begin to like this community : >
cheers
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic