Guest User

What should I grade ?

a guest
Apr 15th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.99 KB | None | 0 0
  1.   public void mst(){
  2.     ArrayList<T> visited = new ArrayList<T>();
  3.     ArrayList<T> unvisited = (ArrayList<T>)this.vertices.clone();
  4.     visited.add(unvisited.remove(0));
  5.  
  6.     while(unvisited.size() > 0){
  7.       T nextVertex = null;
  8.       T startVertex = null;
  9.       int minimumWeight = Integer.MAX_VALUE;
  10.       int visitedSize = visited.size();
  11.       int unvisitedSize = unvisited.size();
  12.  
  13.       for( int i = 0; i < visitedSize; i++ ){
  14.         T fromVertex = visited.get(i);
  15.         for( int j = 0; j < unvisitedSize; j++ ){
  16.           T currentVertex = unvisited.get(j);
  17.           int currentWeight = this.getWeight(fromVertex, currentVertex);
  18.           if( minimumWeight > currentWeight ){
  19.             minimumWeight = currentWeight;
  20.             nextVertex = currentVertex;
  21.             startVertex = fromVertex;
  22.           }
  23.         }
  24.       }
  25.  
  26.       System.out.printf("(%s) - (%s)\n", startVertex, nextVertex);
  27.       unvisited.remove(nextVertex);
  28.       visited.add(nextVertex);
  29.     }
  30.   }
Add Comment
Please, Sign In to add comment