// --------------------------------------------------------------- public void mst() // minimum spanning tree using depth first search { // start at 0 --> mark and push vertexList[0].wasVisited = true; theStack.push(0); while (!theStack.isEmpty()) { int currentVertex = theStack.peek(); // get next unvisited neighbor int v = getAdjUnvisitedVertex(currentVertex); if (v == -1) // no more neighbors theStack.pop(); else { // mark and push the neighbor vertexList[v].wasVisited = true; theStack.push(v); // print out the path we just traveled displayVertex(currentVertex); displayVertex(v); System.out.print(" "); } } // Once stack is empty, we're done...reset flags for (int j = 0; j < nVerts; j++) vertexList[j].wasVisited = false; }