[29] | 1 | //======================================================================= |
---|
| 2 | // Copyright 2001 Jeremy G. Siek, Andrew Lumsdaine, Lie-Quan Lee, |
---|
| 3 | // |
---|
| 4 | // Distributed under the Boost Software License, Version 1.0. (See |
---|
| 5 | // accompanying file LICENSE_1_0.txt or copy at |
---|
| 6 | // http://www.boost.org/LICENSE_1_0.txt) |
---|
| 7 | //======================================================================= |
---|
| 8 | #include <boost/config.hpp> |
---|
| 9 | #include <iostream> |
---|
| 10 | #include <vector> |
---|
| 11 | #include <string> |
---|
| 12 | #include <boost/graph/adjacency_list.hpp> |
---|
| 13 | #include <boost/tuple/tuple.hpp> |
---|
| 14 | enum family |
---|
| 15 | { Jeanie, Debbie, Rick, John, Amanda, Margaret, Benjamin, N }; |
---|
| 16 | int |
---|
| 17 | main() |
---|
| 18 | { |
---|
| 19 | using namespace boost; |
---|
| 20 | const char *name[] = { "Jeanie", "Debbie", "Rick", "John", "Amanda", |
---|
| 21 | "Margaret", "Benjamin" |
---|
| 22 | }; |
---|
| 23 | |
---|
| 24 | adjacency_list <> g(N); |
---|
| 25 | add_edge(Jeanie, Debbie, g); |
---|
| 26 | add_edge(Jeanie, Rick, g); |
---|
| 27 | add_edge(Jeanie, John, g); |
---|
| 28 | add_edge(Debbie, Amanda, g); |
---|
| 29 | add_edge(Rick, Margaret, g); |
---|
| 30 | add_edge(John, Benjamin, g); |
---|
| 31 | |
---|
| 32 | graph_traits < adjacency_list <> >::vertex_iterator i, end; |
---|
| 33 | graph_traits < adjacency_list <> >::adjacency_iterator ai, a_end; |
---|
| 34 | property_map < adjacency_list <>, vertex_index_t >::type |
---|
| 35 | index_map = get(vertex_index, g); |
---|
| 36 | |
---|
| 37 | for (tie(i, end) = vertices(g); i != end; ++i) { |
---|
| 38 | std::cout << name[get(index_map, *i)]; |
---|
| 39 | tie(ai, a_end) = adjacent_vertices(*i, g); |
---|
| 40 | if (ai == a_end) |
---|
| 41 | std::cout << " has no children"; |
---|
| 42 | else |
---|
| 43 | std::cout << " is the parent of "; |
---|
| 44 | for (; ai != a_end; ++ai) { |
---|
| 45 | std::cout << name[get(index_map, *ai)]; |
---|
| 46 | if (boost::next(ai) != a_end) |
---|
| 47 | std::cout << ", "; |
---|
| 48 | } |
---|
| 49 | std::cout << std::endl; |
---|
| 50 | } |
---|
| 51 | return EXIT_SUCCESS; |
---|
| 52 | } |
---|