• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
14 #include <boost/graph/adjacency_list.hpp>
15 
16 /*
17   Sample Output
18 
19   0 <--
20   1 <-- 0
21   2 <-- 1
22   3 <-- 1
23   4 <-- 2  3
24 
25  */
26 
main(int,char * [])27 int main(int, char*[])
28 {
29     using namespace boost;
30     using namespace std;
31     using namespace boost;
32 
33     typedef adjacency_list< listS, vecS, bidirectionalS > Graph;
34     const int num_vertices = 5;
35     Graph g(num_vertices);
36 
37     add_edge(0, 1, g);
38     add_edge(1, 2, g);
39     add_edge(1, 3, g);
40     add_edge(2, 4, g);
41     add_edge(3, 4, g);
42 
43     boost::graph_traits< Graph >::vertex_iterator i, end;
44     boost::graph_traits< Graph >::in_edge_iterator ei, edge_end;
45 
46     for (boost::tie(i, end) = vertices(g); i != end; ++i)
47     {
48         cout << *i << " <-- ";
49         for (boost::tie(ei, edge_end) = in_edges(*i, g); ei != edge_end; ++ei)
50             cout << source(*ei, g) << "  ";
51         cout << endl;
52     }
53     return 0;
54 }
55