reverse_graph.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 <algorithm>
  10. #include <vector>
  11. #include <utility>
  12. #include <iostream>
  13. #include <boost/graph/adjacency_list.hpp>
  14. #include <boost/graph/reverse_graph.hpp>
  15. #include <boost/graph/graph_utility.hpp>
  16. int
  17. main()
  18. {
  19. using namespace boost;
  20. typedef adjacency_list < vecS, vecS, bidirectionalS > Graph;
  21. Graph G(5);
  22. add_edge(0, 2, G);
  23. add_edge(1, 1, G);
  24. add_edge(1, 3, G);
  25. add_edge(1, 4, G);
  26. add_edge(2, 1, G);
  27. add_edge(2, 3, G);
  28. add_edge(2, 4, G);
  29. add_edge(3, 1, G);
  30. add_edge(3, 4, G);
  31. add_edge(4, 0, G);
  32. add_edge(4, 1, G);
  33. std::cout << "original graph:" << std::endl;
  34. print_graph(G, get(vertex_index, G));
  35. std::cout << std::endl << "reversed graph:" << std::endl;
  36. #if defined(BOOST_MSVC) && BOOST_MSVC <= 1300 // avoid VC++ bug...
  37. reverse_graph<Graph> R(G);
  38. print_graph(R, get(vertex_index, G));
  39. #else
  40. print_graph(make_reverse_graph(G), get(vertex_index, G));
  41. #endif
  42. return EXIT_SUCCESS;
  43. }