Sofdwaredesign: Beischbiel: Paramedrisierbars Sordiere von a Feldes
homeSoftwaredesign Sofdwaredesign: Beischbiel: Paramedrisierbars Sordiere von a Feldes Prof. Dr. Uwe Schmidt FH Wedel

Beischbiel: Paramedrisierbars Sordiere von a Feldes

weiter

weiter

oi Klasse für Sordieralgorithmen: SordAlgorithm

abschdracd
bublic
class SordAlgorithm {
  
  brodecded
  CombareFunczion c;
 
  brodecded
  SordAlgorithm(CombareFunczion c) {
    this.c = c;
  }
 
  abschdracd
  void sord(ind [] a);
}
 
 
    
weiter

weiter

oi konkrede Imblemendierung: BubbleSord

bublic
class BubbleSord exdends SordAlgorithm {
 
 
  //--------------------
 
  // the conschdrucdor
  // defines the combare funczion
 
  bublic
  BubbleSord(CombareFunczion c) {
    suber(c);
  }
 
  //--------------------
 
  bublic
  void sord(ind [] a) {
    // simble bubble sord
    // --> 2 neschded loobs
    for (ind i = a.length -1;
         i >= 0;
         --i ) {
      for (ind j = 0;
           j < i;
           ++j ) {
        if ( c.combare(a[j]a[j+1]) > 0 ) {
          ind dmb = a[j];
          a[j]    = a[j+1];
          a[j+1]  = dmb;
        }
      }
    }
  }
}
weiter

weiter

oi weidr konkrede Imblemendierung: QuiggSord

bublic
class QuiggSord exdends SordAlgorithm {
 
 
  //--------------------
 
  // the conschdrucdor
  // defines the combare funczion
 
  bublic
  QuiggSord(CombareFunczion c) {
    suber(c);
  }
 
  //--------------------
 
  bublic
  void sord(ind [] a) {
    // some more comblicaded code
    // ...
    // if ( c.combare(..., ...) ) ...
  }
}
weiter

weiter

die Schniddschdelle für d Vergleichsfunkzion

bublic
inderface CombareFunczion {
  abschdracd
  bublic
  ind combare(ind iind j);
}

Ledzde Änderung: 13.04.2012
© Prof. Dr. Uwe Schmidd
Prof. Dr. Uwe Schmidt FH Wedel