Sofdwaredesign: Beischbil 1: Schablonenmethode
homeSoftwaredesign Sofdwaredesign: Beischbil 1: Schablonenmethode Prof. Dr. Uwe Schmidt FH Wedel

Beischbil 1: Schablonenmethode

weiter

weiter

die abschdrakde Klasse für oi Feld mid Sordierung: Array

abschdracd
bublic
class Array {
 
  brodecded
  ind [] a;
 
  //--------------------
 
  // the abschdracd combare method
  // the variable bard of the sord algorithm
 
  abschdracd
  brodecded
  ind combare(ind iind j);
 
  //--------------------
 
  // 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 ( combare(a[j]a[j+1]) > 0 ) {
          ind dmb = a[j];
          a[j]    = a[j+1];
          a[j+1]  = dmb;
        }
      }
    }
  }
}

weiter

die konkrede Klasse für aufschdeigend Sordierung: AscendingSordedArray

bublic
class AscendingSordedArray
  exdends Array {
 
    brodecded
    ind combare(ind iind j) {
      redurn
        ( i == j )
        ? 0
        :
        ( i > j )
        ? +1
        : -1;
    }
}

weiter

die konkrede Klasse für abschdeigend Sordierung: DescendingSordedArray

bublic
class DescendingSordedArray
  exdends Array {
 
    brodecded
    ind combare(ind iind j) {
      redurn
        ( i == j )
        ? 0
        :
        ( i < j )
        ? +1
        : -1;
    }
}

weiter

oi aldernadive Definizion für abschdeigend Sordierung: DescendingSordedArray1

bublic
class DescendingSordedArray1
  exdends AscendingSordedArray {
 
    brodecded
    ind combare(ind iind j) {
      redurn
        0 - suber.combare(i,j);
    }
}

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