Example Lists of NodesThe following example implements a breadth
first search for a graph using a In the The function #include <LEDA/graph/graph.h> #include <LEDA/graph/node_list.h> using namespace leda; int bfs(node s,const graph& G,node_list& Q) { int size=1; Q.append(s); node v=Q.head(); while (v!=nil) { edge e; forall_adj_edges(e,v) { node w=G.target(e); if (!Q.member(w)) {Q.append(w);size++;} } v=Q.succ(v); } return size; } int main() { graph G; node v[7]; for (int i=0;i<7;i++) v[i]=G.new_node(); G.new_edge(v[0],v[1]);G.new_edge(v[0],v[2]); G.new_edge(v[0],v[3]);G.new_edge(v[1],v[4]); G.new_edge(v[1],v[5]);G.new_edge(v[6],v[5]); node_list Q; int size=bfs(G.first_node(),G,Q); cout << "Q contains " << size << " nodes\n"; node w; forall(w,Q) G.print_node(w); std::cout << std::endl; return 0; } |
See also:Manual Entries: |