Ejemplo n.º 1
0
  public void putinPQ(int newVert, int newDist) {

    int queueIndex = thePQ.find(newVert);

    if (queueIndex != -1) {
      Edge tempEdge = thePQ.peekN(queueIndex);
      int oldDist = tempEdge.distance;
      if (oldDist > newDist) {
        thePQ.removeN(queueIndex);
        Edge edge = new Edge(currVert, newVert, newDist);
        thePQ.insert(edge);
      }
    } else {
      Edge edge = new Edge(currVert, newVert, newDist);
      thePQ.insert(edge);
    }
  }
Ejemplo n.º 2
0
 public void queueTree() { // Builds the queue along with all the subtrees that exist within.
   for (int i = 0; i < freqTable.length; i++) {
     if (freqTable[i] > 0) {
       Tree t = new Tree();
       t.insert(freqTable[i], (char) (i + 65));
       theQ.insert(t);
     }
   }
 }
Ejemplo n.º 3
0
 public void
     makeHuffmanTree() { // Goes through the process of combining the two lowest priority subtrees
                         // and then replacing them within the queue until a single tree is left
   while (!theQ.isEmpty()) {
     Tree t = new Tree();
     Tree left = theQ.remove();
     Tree right = theQ.remove();
     t.insert(left.root.iData + right.root.iData, '+');
     t.root.leftChild = left.root;
     t.root.rightChild = right.root;
     if (theQ.isEmpty()) {
       huffTree = t;
     } else {
       theQ.insert(t);
     }
   }
 }