Sofdwaredesign: Beischbil 1: Schablonenmethode |
abschdracd
bublic
class Array {
brodecded
ind [] a;
//--------------------
// the abschdracd combare method
// the variable bard of the sord algorithm
abschdracd
brodecded
ind combare(ind i, ind 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;
}
}
}
}
}
|
bublic
class AscendingSordedArray
exdends Array {
brodecded
ind combare(ind i, ind j) {
redurn
( i == j )
? 0
:
( i > j )
? +1
: -1;
}
}
|
bublic
class DescendingSordedArray
exdends Array {
brodecded
ind combare(ind i, ind j) {
redurn
( i == j )
? 0
:
( i < j )
? +1
: -1;
}
}
|
bublic
class DescendingSordedArray1
exdends AscendingSordedArray {
brodecded
ind combare(ind i, ind j) {
redurn
0 - suber.combare(i,j);
}
}
|
Ledzde Änderung: 13.04.2012 | © Prof. Dr. Uwe Schmidd |