Back to index

wims  3.65+svn20090927
Static Public Member Functions | Static Private Member Functions
rene.util.sort.Sorter Class Reference

Quick sort implementation. More...

List of all members.

Static Public Member Functions

static void sort (SortObject v[])
static void sort (SortObject v[], int n)
static void sort (Vector v)
static void QuickSort (SortObject a[], int lo0, int hi0)
static void QuickSort (Object a[], int lo0, int hi0)
static void main (String args[]) throws IOException

Static Private Member Functions

static void swap (SortObject a[], int i, int j)
static void swap (Object a[], int i, int j)

Detailed Description

Quick sort implementation.

Sorts an array or a vector of SortObject.

Definition at line 11 of file Sorter.java.


Member Function Documentation

static void rene.util.sort.Sorter.main ( String  args[]) throws IOException [inline, static]

Definition at line 88 of file Sorter.java.

       {      BufferedReader in=new BufferedReader(
                     new InputStreamReader(System.in));
              Vector v=new Vector();
              while (true)
              {      String line=in.readLine();
                     if (line==null) break;
                     v.addElement(new SortString(line));
              }
              in.close();
              sort(v);
              Enumeration e=v.elements();
              String last=null;
              while (e.hasMoreElements())
              {      String s=((SortString)e.nextElement()).toString();
                     if (last==null || !s.equals(last))
                     {      System.out.println(s);
                            last=s;
                     }
              }
       }

Here is the call graph for this function:

static void rene.util.sort.Sorter.QuickSort ( SortObject  a[],
int  lo0,
int  hi0 
) [inline, static]

Definition at line 28 of file Sorter.java.

       {      int lo = lo0;
              int hi = hi0;
              SortObject mid;

              if ( hi0 > lo0)
              {      mid = a[ ( lo0 + hi0 ) / 2 ];
                     while( lo <= hi )
                     {      while( ( lo < hi0 ) && ( a[lo].compare(mid)<0 ) )
                               ++lo;
                            while( ( hi > lo0 ) && ( a[hi].compare(mid)>0 ) )
                               --hi;
                            if( lo <= hi ) 
                            {      swap(a, lo, hi);
                                   ++lo;
                                   --hi;
                            }
                     }
                     if( lo0 < hi ) QuickSort( a, lo0, hi );
                     if( lo < hi0 ) QuickSort( a, lo, hi0 );
              }      
       }

Here is the call graph for this function:

Here is the caller graph for this function:

static void rene.util.sort.Sorter.QuickSort ( Object  a[],
int  lo0,
int  hi0 
) [inline, static]

Definition at line 58 of file Sorter.java.

       {      int lo = lo0;
              int hi = hi0;
              SortObject mid;

              if ( hi0 > lo0)
              {      mid = (SortObject) a[ ( lo0 + hi0 ) / 2 ];
                     while( lo <= hi )
                     {      while( ( lo < hi0 ) && ( ((SortObject)a[lo]).compare(mid)<0 ) )
                               ++lo;
                            while( ( hi > lo0 ) && ( ((SortObject)a[hi]).compare(mid)>0 ) )
                               --hi;
                            if( lo <= hi ) 
                            {      swap(a, lo, hi);
                                   ++lo;
                                   --hi;
                            }
                     }
                     if( lo0 < hi ) QuickSort( a, lo0, hi );
                     if( lo < hi0 ) QuickSort( a, lo, hi0 );
              }
       }

Here is the call graph for this function:

static void rene.util.sort.Sorter.sort ( SortObject  v[]) [inline, static]

Definition at line 12 of file Sorter.java.

{      static public void sort (SortObject v[])
       {      QuickSort(v,0,v.length-1);
       }

Here is the call graph for this function:

Here is the caller graph for this function:

static void rene.util.sort.Sorter.sort ( SortObject  v[],
int  n 
) [inline, static]

Definition at line 16 of file Sorter.java.

       {      QuickSort(v,0,n-1);
       }

Here is the call graph for this function:

static void rene.util.sort.Sorter.sort ( Vector  v) [inline, static]

Definition at line 20 of file Sorter.java.

       {      SortObject o[]=new SortObject[v.size()];
              v.copyInto(o);
              sort(o);
              for (int i=0; i<o.length; i++)
                     v.setElementAt(o[i],i);
       }

Here is the call graph for this function:

static void rene.util.sort.Sorter.swap ( SortObject  a[],
int  i,
int  j 
) [inline, static, private]

Definition at line 51 of file Sorter.java.

       {      SortObject T;
              T = a[i]; 
              a[i] = a[j];
              a[j] = T;
       }

Here is the caller graph for this function:

static void rene.util.sort.Sorter.swap ( Object  a[],
int  i,
int  j 
) [inline, static, private]

Definition at line 81 of file Sorter.java.

       {      Object T;
              T = a[i]; 
              a[i] = a[j];
              a[j] = T;
       }

The documentation for this class was generated from the following file: