in_edges.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. //=======================================================================
  2. // Copyright 1997, 1998, 1999, 2000 University of Notre Dame.
  3. // Authors: Andrew Lumsdaine, Lie-Quan Lee, Jeremy G. Siek
  4. //
  5. // Distributed under the Boost Software License, Version 1.0. (See
  6. // accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. //=======================================================================
  9. #include <boost/config.hpp>
  10. #include <iostream>
  11. #include <vector>
  12. #include <utility>
  13. #include <boost/graph/adjacency_list.hpp>
  14. /*
  15. Sample Output
  16. 0 <--
  17. 1 <-- 0
  18. 2 <-- 1
  19. 3 <-- 1
  20. 4 <-- 2 3
  21. */
  22. int main(int , char* [])
  23. {
  24. using namespace boost;
  25. using namespace std;
  26. using namespace boost;
  27. typedef adjacency_list<listS,vecS,bidirectionalS> Graph;
  28. const int num_vertices = 5;
  29. Graph g(num_vertices);
  30. add_edge(0, 1, g);
  31. add_edge(1, 2, g);
  32. add_edge(1, 3, g);
  33. add_edge(2, 4, g);
  34. add_edge(3, 4, g);
  35. boost::graph_traits<Graph>::vertex_iterator i, end;
  36. boost::graph_traits<Graph>::in_edge_iterator ei, edge_end;
  37. for(boost::tie(i,end) = vertices(g); i != end; ++i) {
  38. cout << *i << " <-- ";
  39. for (boost::tie(ei,edge_end) = in_edges(*i, g); ei != edge_end; ++ei)
  40. cout << source(*ei, g) << " ";
  41. cout << endl;
  42. }
  43. return 0;
  44. }