コード例 #1
0
ファイル: Graph.java プロジェクト: pritish5699/DataStructure
  public void mstw() {
    currVert = 0;

    while (nTree < nVerts - 1) {

      vertextList[currVert].isInTree = true;
      nTree++;

      for (int j = 0; j < nVerts; j++) {

        int distance = adjMat[currVert][j];

        if (j == currVert || vertextList[j].isInTree || distance == INFINITY) continue;

        putinPQ(j, distance);
      }

      if (thePQ.size() == 0) {
        System.out.println("Graph is not Connected.");
        return;
      }

      Edge edge = thePQ.removeMin();
      int srcVert = edge.srcVert;
      currVert = edge.destVert;

      System.out.print(vertextList[srcVert].label);
      System.out.print(vertextList[this.currVert].label);
      System.out.print(" ");
    }

    for (int j = 0; j < nVerts; j++) vertextList[j].isInTree = false;
  }
コード例 #2
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);
     }
   }
 }
コード例 #3
0
ファイル: Graph.java プロジェクト: pritish5699/DataStructure
  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);
    }
  }
コード例 #4
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);
     }
   }
 }
コード例 #5
0
ファイル: PriorityQSort.java プロジェクト: dcsch/jogl
  /* really __gl_pqSortMinimum */
  @Override
  Object pqMinimum() {
    Object sortMin, heapMin;

    if (size == 0) {
      return heap.pqMinimum();
    }
    sortMin = keys[order[size - 1]];
    if (!heap.pqIsEmpty()) {
      heapMin = heap.pqMinimum();
      if (PriorityQ.LEQ(leq, heapMin, sortMin)) {
        return heapMin;
      }
    }
    return sortMin;
  }
コード例 #6
0
ファイル: PriorityQSort.java プロジェクト: dcsch/jogl
 private static boolean GT(
     final jogamp.opengl.glu.tessellator.PriorityQ.Leq leq, final Object x, final Object y) {
   return (!PriorityQ.LEQ(leq, x, y));
 }