This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to use quick sort algo

 
harish goyal
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to do quick sort in java.
suppose i have a rray of 10 element;
int a[] ={ 4,5,2,8,4,6,2,4,8,9)
i want to sort them .
in quick sort . we pivot one element and then
find all the nummber below it and about it.
than we sort it seprately.

please help me to understand this concept of quick sort
i want to use quick sort algo in java to sort these elements in java
can anyone help
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Writing an implementation of Quicksort is going to be a fairly significant job. Using an existing implementation to sort some stuff is very easy. Can you clarify which you have to do? For example, a school assignment might require you to write your own but a job assignment would deliver better results sooner by using what's in the Java libraries.
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Quicksort is generally credited to be the fastest sorting algorithm in most cases, but merge sort isn't bad either. And it's implemented in the Collections.sort methods, so you get it for free
[ August 29, 2005: Message edited by: Ulf Dittmer ]
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by harish goyal:
how to do quick sort in java.
suppose i have a rray of 10 element;
int a[] ={ 4,5,2,8,4,6,2,4,8,9)
i want to sort them .
in quick sort . we pivot one element and then
find all the nummber below it and about it.
than we sort it seprately.

please help me to understand this concept of quick sort
i want to use quick sort algo in java to sort these elements in java
can anyone help

Typically, you should just do

Unless you want to implement quick sort yourself. If so, there are plenty of descriptions about the algorithm online or in any decent text about data structures. Typically, the description will include pseudocode that you can easily translate into Java. If you need help with this translation, let us know.

Layne
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic