Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/graph/example/iteration_macros.cpp @ 30

Last change on this file since 30 was 29, checked in by landauf, 17 years ago

updated boost from 1_33_1 to 1_34_1

File size: 1.4 KB
Line 
1//=======================================================================
2// Copyright 2001 Indiana University.
3// Author: 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
10
11#include <boost/graph/adjacency_list.hpp>
12#include <boost/graph/iteration_macros.hpp>
13
14enum family { Jeanie, Debbie, Rick, John, Amanda, Margaret, Benjamin, N };
15
16int main()
17{
18  using namespace boost;
19  const char *name[] = { "Jeanie", "Debbie", "Rick", "John", "Amanda",
20    "Margaret", "Benjamin"
21  };
22
23  adjacency_list <> g(N);
24  add_edge(Jeanie, Debbie, g);
25  add_edge(Jeanie, Rick, g);
26  add_edge(Jeanie, John, g);
27  add_edge(Debbie, Amanda, g);
28  add_edge(Rick, Margaret, g);
29  add_edge(John, Benjamin, g);
30
31  graph_traits<adjacency_list <> >::vertex_iterator i, end;
32  graph_traits<adjacency_list <> >::adjacency_iterator ai, a_end;
33  property_map<adjacency_list <>, vertex_index_t>::type
34    index_map = get(vertex_index, g);
35
36  BGL_FORALL_VERTICES(i, g, adjacency_list<>) {
37    std::cout << name[get(index_map, i)];
38
39    if (out_degree(i, g) == 0)
40      std::cout << " has no children";
41    else
42      std::cout << " is the parent of ";
43
44    BGL_FORALL_ADJACENT(i, j, g, adjacency_list<>)
45      std::cout << name[get(index_map, j)] << ", ";
46    std::cout << std::endl;
47  }
48  return EXIT_SUCCESS;
49}
Note: See TracBrowser for help on using the repository browser.