/insert edges adjacent to currentvert into pq for(int = <nvertsj++/for each vertexif( ==currentvert/skip if it' us continueif(vertexlist[jisintree/skip if in the tree continueint distance adjmat[currentvert][ ]ifdistance =infinity/skip if no edge continueputinpq(jdistance)/put it in pq (maybeif(thepq size()== /no vertices in pqsystem out println(graph not connected")return/remove edge with minimum distancefrom pq edge theedge thepq removemin()int sourcevert theedge srcvertcurrentvert theedge destvert/display edge from source to current system out printvertexlist[sourcevertlabel )system out printvertexlist[currentvertlabel )system out print(")/end while(not all verts in tree/mst is complete for(int = <nvertsj++/unmark vertices vertexlist[jisintree false/end mstw /public void putinpq(int newvertint newdist/is there another edge with the same destination vertexint queueindex thepq find(newvert)if(queueindex !- /got edge' index edge tempedge thepq peekn(queueindex)/get edge int olddist tempedge distanceif(olddist newdist/if new edge shorterthepq removen(queueindex)/remove old edge edge theedge new edge(currentvertnewvertnewdist)thepq insert(theedge)/insert new edge