import java.util.Arrays;
import java.util.Comparator;
public abstract class TriediaciAlgoritmus<E> {
protected E[] p;
private Comparator<E> comparator;
private int pocetPorovnani;
private int pocetVymen;
protected int porovnaj(int idx1, int idx2) {
pocetPorovnani++;
if (comparator != null)
return comparator.compare(p[idx1], p[idx2]);
else
return ((Comparable<E>) p[idx1]).compareTo(p[idx2]);
}
protected void vymen(int idx1, int idx2) {
pocetVymen++;
E pom = p[idx1];
p[idx1] = p[idx2];
p[idx2] = pom;
}
protected void vypisPole() {
System.out.println(Arrays.toString(p));
}
public void utried(E[] p) {
utried(p, null);
}
public void utried(E[] p, Comparator<E> comparator) {
if (p == null)
throw new NullPointerException("p");
if (comparator == null && p.length > 0 && !(p[0] instanceof Comparable<?>))
throw new NullPointerException("comparator");
this.comparator = comparator;
this.p = p;
vypisPole();
pocetPorovnani = 0;
pocetVymen = 0;
utried(p.length);
vypisPole();
this.p = null;
}
protected abstract void utried(int dlzkaPola);
public int getPocetPorovnani() {
return pocetPorovnani;
}
public int getPocetVymen() {
return pocetVymen;
}
}