Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_34_1/libs/graph/example/dfs-parenthesis.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.3 KB
Line 
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/graph/graphviz.hpp>
9#include <boost/graph/depth_first_search.hpp>
10
11char name[] = "abcdefghij";
12
13struct parenthesis_visitor : public boost::default_dfs_visitor
14{
15  template <class Vertex, class Graph> void
16  start_vertex(Vertex v, const Graph &)
17  {
18    std::cout << ' ';
19  }
20  template <class Vertex, class Graph> void
21  discover_vertex(Vertex v, const Graph &)
22  {
23    std::cout << "(" << name[v] << ' ';
24  }
25  template <class Vertex, class Graph> void
26  finish_vertex(Vertex v, const Graph &)
27  {
28    std::cout << ' ' << name[v] << ")";
29  }
30};
31
32int
33main()
34{
35  using namespace boost;
36  GraphvizGraph g;
37  read_graphviz("figs/dfs-example.dot", g);
38  graph_traits < GraphvizGraph >::edge_iterator e, e_end;
39  for (tie(e, e_end) = edges(g); e != e_end; ++e)
40    std::cout << '(' << name[source(*e, g)] << ' '
41      << name[target(*e, g)] << ')' << std::endl;
42  parenthesis_visitor
43    paren_vis;
44  depth_first_search(g, visitor(paren_vis));
45  std::cout << std::endl;
46  return 0;
47}
Note: See TracBrowser for help on using the repository browser.