Example #1
0
 @Override
 public void insert(int a) {
   Binomikeko uusikeko = new Binomikeko();
   BinomiNode keonEkapuu = new BinomiNode(a);
   uusikeko.head = keonEkapuu;
   yhdistaKeot(uusikeko);
 }
Example #2
0
  private int extractMin() { // extract-Min
    BinomiNode minEd = null;
    int min = Integer.MAX_VALUE;
    Binomikeko tmp = new Binomikeko();
    BinomiNode edellinen;
    BinomiNode i = this.head;
    if (i == null) {
      throw new EmptyStackException();
    }
    edellinen = null;
    do {
      if (i.getArvo() <= min) {
        min = i.getArvo();
        minEd = edellinen;
      }
      edellinen = i;
      i = i.getSisar();
    } while (i != null);

    BinomiNode poistettava;
    if (minEd == null) { // head on ainoa jolla ei isosiskoa
      poistettava = this.head;
      this.head = poistettava.getSisar();
    } else {
      poistettava = minEd.getSisar();
      minEd.setSisar(poistettava.getSisar());
    }

    BinomiNode l = poistettava.getlapsi();
    if (l == null) {
      return min;
    }
    // on lapsia, yhdistetään ne
    while (l.getSisar() != null) {
      BinomiNode next = l.getSisar();
      l.setSisar(tmp.head);
      tmp.head = l;
      l = next;
    }
    l.setSisar(tmp.head);
    tmp.head = l;
    this.yhdistaKeot(tmp);
    return min;
  }