weighted graphs the algorithm is carried out in the while loopwhich terminates when all vertices are in the tree within this loop the following activities take place the current vertex is placed in the tree the edges adjacent to this vertex are placed in the priority queue (if appropriate the edge with the minimum weight is removed from the priority queue the destination vertex of this edge becomes the current vertex let' look at these steps in more detail in step the currentvert is placed in the tree by marking its isintree field in step the edges adjacent to this vertex are considered for insertion in the priority queue the edges are examined by scanning across the row whose number is currentvert in the adjacency matrix an edge is placed in the queue unless one of these conditions is truethe source and destination vertices are the same the destination vertex is in the tree there is no edge to this destination if none of these conditions are truethe putinpq(method is called to put the edge in the priority queue actuallythis routine doesn' always put the edge in the queue eitheras we'll see in moment in step the edge with the minimum weight is removed from the priority queue this edge and its destination vertex are added to the treeand the source vertex (currentvertand destination vertex are displayed at the end of mstw()the vertices are removed from the tree by resetting their isintree variables that isn' strictly necessary in this program because only one tree is created from the data howeverit' good housekeeping to restore the data to its original form when you finish with it as we notedthe priority queue should contain only one edge with given destination vertex the putinpq(method makes sure this is true it calls the find(method of the priorityq classwhich has been doctored to find the edge with specified destination vertex if there is no such vertexand find(therefore returns - then putinpq(simply inserts the edge into the priority queue howeverif such an edge does existputinpq(checks to see whether the existing edge or the new proposed edge has the lower weight if it' the old edgeno change is necessary if the new one has lower weightthe old edge is removed from the queue and the new one is installed here' the code for putinpq()