codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  java  happygirl at 05:35 on Friday, March 03, 2006
 

I want to sort an java Object such as : StudentAge, this program will using below algorithm to sort it , how i going to implement it ?

public static void quicksort(Object [] a, int left, int right)
{

if (left < right) {
int p = partition(a, left, right);
quicksort(a, left, p-1);
quicksort(a, p+1, right);
}


public static int partition(Object [] a, int left, int right)
{

Object pivot = a[left];
int p = left;
for (int r = left+1; r <= right; r++)
{
if(((Comparable)a[r]).compareTo((Comparable)pivot) < 0)
{
a[p] = a[r];
a[r] = a[p+1];
a[p+1] = pivot;
p++;
}
}
return p;
}


the output must be like that :

before sorting :
Lisa : 30
Andy : 25
Winson :19

After sorting :

winson : 19
Andy : 25
Lisa : 30











CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
//








Recent Forum Threads
•  Re: Security - Code verify
•  Job @ EarlySail
•  Job @ EarlySail (perl)
•  IPC problem
•  Re: import contacts of msn/yahoo
•  Cookies and Threads C++
•  right justify a background in a table?
•  Help with Loop (C++/MFC)
•  Help with Loop (C++/MFC)


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2007