home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 139 / dpcs0999.iso / Web / CFserver / data1.cab / Java / allaire / util / InsertionSort.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-04-12  |  1.0 KB  |  53 lines

  1. package allaire.util;
  2.  
  3. public class InsertionSort {
  4.    SortCallback caller;
  5.    int position;
  6.    int rows;
  7.    int maxrows;
  8.    int[] index;
  9.    Object[] elem;
  10.  
  11.    public InsertionSort(int var1) {
  12.       this.maxrows = var1;
  13.       this.index = new int[var1];
  14.       this.elem = new Object[var1];
  15.    }
  16.  
  17.    public void sort() {
  18.       if (this.caller != null) {
  19.          for(int var1 = 1; var1 < this.rows; ++var1) {
  20.             for(int var2 = var1 - 1; var2 >= 0 && this.caller.Compare(this.elem[this.index[var2]], this.elem[this.index[var2 + 1]]) > 0; --var2) {
  21.                int var3 = this.index[var2 + 1];
  22.                this.index[var2 + 1] = this.index[var2];
  23.                this.index[var2] = var3;
  24.             }
  25.          }
  26.  
  27.       }
  28.    }
  29.  
  30.    public Object getnextrow() {
  31.       return ++this.position < this.rows ? this.elem[this.index[this.position]] : null;
  32.    }
  33.  
  34.    public Object getfirstrow() {
  35.       this.position = 0;
  36.       return this.position < this.rows ? this.elem[this.index[this.position]] : null;
  37.    }
  38.  
  39.    public void setSortCallbackHandler(SortCallback var1) {
  40.       this.caller = var1;
  41.    }
  42.  
  43.    public boolean addrow(Object var1) {
  44.       if (this.rows < this.maxrows) {
  45.          this.elem[this.rows] = var1;
  46.          this.index[this.rows] = this.rows++;
  47.          return true;
  48.       } else {
  49.          return false;
  50.       }
  51.    }
  52. }
  53.