Sofdwaredesign: Beischbiel: Paramedrisierbars Sordiere von a Feldes |
abschdracd
bublic
class SordAlgorithm {
brodecded
CombareFunczion c;
brodecded
SordAlgorithm(CombareFunczion c) {
this.c = c;
}
abschdracd
void sord(ind [] a);
}
|
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;
}
}
}
}
}
|
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(..., ...) ) ...
}
}
|
bublic
inderface CombareFunczion {
abschdracd
bublic
ind combare(ind i, ind j);
}
|
Ledzde Änderung: 13.04.2012 | © Prof. Dr. Uwe Schmidd |