Here's a first try for traversing a graph to print out each element:
List observed = new List() //this will hold things we've seen, but haven't visited (printed) yet
observed.add(startVertex) //our starting vertex
while(!observed.isEmpty())
{
Vertex v=observed.getNext()
print("Visiting vertex "+v)
for each of v's neighbors n:
observed.add(n) //note: n isn't 'visited' at this point, just observed
}
print("Done!")
What's wrong with this version?