src/work/iterator_bfs_dfs_demo.cc
changeset 64 72bd463289a9
parent 45 8fe92d6829e8
child 107 8d62f0072ff0
equal deleted inserted replaced
0:8ab4251c10d1 1:a05344dec5a2
   179       std::cout<<std::endl;
   179       std::cout<<std::endl;
   180       bfs.next();
   180       bfs.next();
   181     }
   181     }
   182   }
   182   }
   183   
   183   
       
   184   {
       
   185     std::cout << "iterator bfs demo 2 ..." << std::endl;
       
   186     //ListGraph::NodeMap<bool> reached(G, false);
       
   187     //reached.set(s, true);
       
   188     //std::queue<ListGraph::OutEdgeIt> bfs_queue;
       
   189     //bfs_queue.push(G.first<OutEdgeIt>(s));
       
   190     BfsIterator2< ListGraph, ListGraph::OutEdgeIt, ListGraph::NodeMap<bool> > bfs(G);
       
   191     bfs.pushAndSetReached(s);
       
   192     while (!bfs.finished()) {
       
   193       if (OutEdgeIt(bfs).valid()) {
       
   194 	std::cout << "OutEdgeIt: " << bfs; 
       
   195 	std::cout << " aNode: " << G.aNode(bfs); 
       
   196 	std::cout << " bNode: " << G.bNode(bfs) << " ";
       
   197       } else { 
       
   198 	std::cout << "OutEdgeIt: " << "invalid"; 
       
   199 	std::cout << " aNode: " << G.aNode(bfs); 
       
   200 	std::cout << " bNode: " << "invalid" << " ";
       
   201       }
       
   202       if (bfs.isBNodeNewlyReached()) { 
       
   203 	std::cout << "bNodeIsNewlyReached ";
       
   204       } else { 
       
   205 	std::cout << "bNodeIsNotNewlyReached ";
       
   206       } 
       
   207       if (bfs.isANodeExamined()) { 
       
   208 	std::cout << "aNodeIsExamined ";
       
   209       } else { 
       
   210 	std::cout << "aNodeIsNotExamined ";
       
   211       } 
       
   212       std::cout<<std::endl;
       
   213       ++bfs;
       
   214     }
       
   215   }
       
   216   
       
   217 
       
   218 
   184 
   219 
   185   {
   220   {
   186     std::cout << "iterator dfs demo 1..." << std::endl;
   221     std::cout << "iterator dfs demo 1..." << std::endl;
   187     ListGraph::NodeMap<bool> reached(G, false);
   222     ListGraph::NodeMap<bool> reached(G, false);
   188     reached.set(s, true);
   223     reached.set(s, true);