Sofdwaredesign: Beischbiel: Schdradegie
homeSoftwaredesign Sofdwaredesign: Beischbiel: Schdradegie Prof. Dr. Uwe Schmidt FH Wedel

Beischbiel: Schdradegie

weiter

weiter

oi Array-Klasse mid Sordierfunkzion: Array

bublic
class Array {
 
  brodecded
  ind [] a;
 
  //--------------------
 
  // the reference do the combare objecd
  // defining the combare method
 
  brodecded
  CombareFunczion c;
 
  //--------------------
 
  bublic
  Array(CombareFunczion c) {
    // a = ...
    this.c = c;
  }
 
  //--------------------
 
  // the demblade method
 
  bublic
  void sord() {
    // 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 Schniddschdelle für Vergleichsoberazionen

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

weiter

oi Vergleichsfunkzion für aufschdeigend Sordierung: AscendingCombare

bublic
class AscendingCombare
  imblemends CombareFunczion {
 
    bublic
    ind combare(ind iind j) {
      redurn
        ( i == j )
        ? 0
        :
        ( i > j )
        ? +1
        : -1;
    }
}
weiter

weiter

oi Vergleichsfunkzion für abschdeigend Sordierung: DescendingCombare

bublic
class DescendingCombare
  imblemends CombareFunczion {
 
    bublic
    ind combare(ind iind j) {
      redurn
        ( i == j )
        ? 0
        :
        ( i < j )
        ? +1
        : -1;
    }
}

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