language: C++ 4.7.2 (gcc-4.7.2)
date: 493 days 9 hours ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/topological_sort.hpp>
#include <iostream>
 
using namespace boost;
using namespace std;
 
int main() {
 
// Create a n adjacency list, add some vertices.
boost::adjacency_list<listS, vecS, directedS> g;
/*
boost::add_vertex(0,g);
boost::add_vertex(1,g);
boost::add_vertex(2,g);
boost::add_vertex(3,g);
boost::add_vertex(4,g);
boost::add_vertex(5,g);
boost::add_vertex(6,g);
*/
 
// Add edges between vertices.
boost::add_edge(0, 3, g);
boost::add_edge(1, 3, g);
boost::add_edge(1, 4, g);
boost::add_edge(2, 1, g);
boost::add_edge(3, 5, g);
boost::add_edge(4, 6, g);
boost::add_edge(5, 6, g);
 
// Perform a topological sort.
std::list<int> topo_order;
boost::topological_sort(g, std::front_inserter(topo_order));
 
// Print the results.
for(std::list<int>::const_iterator i = topo_order.begin();
    i != topo_order.end();
    ++i)
{
    cout << *i << endl;
}
 
 
}