Here's some pseudo-code for traversing a graph to print out each element visited:
List observed = new List() //this will hold things we've seen, but haven't visited (printed) yet
observed.add(startVertex) //our starting vertex
startVertex.marked=true //mark it so we don't visit it more than once
while(!observed.isEmpty())
{
Vertex v=observed.getNext()
print("Visiting vertex "+v)
for each of v's neighbors n:
if(n.marked) continue //already observed it; ignore
else
{
observed.add(n) //note: n isn't 'visited' at this point, just observed
n.marked=true
}
}
print("Done!")
What ADT should we use for 'List'?