src/work/marci/top_sort_test.cc
author marci
Mon, 10 May 2004 16:31:48 +0000
changeset 597 a6e2b02f496a
parent 557 9c0ce0a1f000
child 609 0566ac97809b
permissions -rw-r--r--
bfs, dfs docs
marci@549
     1
// -*- c++ -*-
marci@549
     2
#include <iostream>
marci@549
     3
#include <fstream>
marci@549
     4
#include <list>
marci@549
     5
marci@549
     6
#include <hugo/dimacs.h>
marci@549
     7
#include <bfs_dfs_misc.h>
marci@549
     8
#include <list_graph.h>
marci@557
     9
#include <hugo/graph_wrapper.h>
marci@577
    10
#include <hugo/maps.h>
marci@549
    11
marci@549
    12
using namespace hugo;
marci@549
    13
marci@549
    14
int main() {
marci@549
    15
  typedef ListGraph Graph;
marci@549
    16
  Graph g;
marci@552
    17
  readDimacs(std::cin, g); 
marci@552
    18
  {
marci@552
    19
    std::list<Graph::Node> l;
marci@577
    20
    NullMap<Graph::Node, Graph::Edge> pred;
marci@577
    21
    topSort(g, l, pred);
marci@552
    22
    std::cout << "Leaving order of dfs which is pretopological..." << std::endl;
marci@552
    23
    for(std::list<Graph::Node>::const_iterator i=l.begin(); i!=l.end(); ++i) {
marci@552
    24
      std::cout << *i << " ";
marci@552
    25
    }
marci@552
    26
    std::cout << std::endl;
marci@549
    27
  }
marci@552
    28
  
marci@552
    29
  {
marci@552
    30
    typedef RevGraphWrapper<Graph> GW;
marci@552
    31
    GW gw(g);
marci@552
    32
    std::list<GW::Node> l;
marci@577
    33
    NullMap<GW::Node, GW::Edge> pred;
marci@577
    34
    topSort(gw, l, pred);
marci@552
    35
    std::cout << "Same in the revered oriented graph..." << std::endl;
marci@552
    36
    for(std::list<GW::Node>::const_iterator i=l.begin(); i!=l.end(); ++i) {
marci@552
    37
      std::cout << *i << " ";
marci@552
    38
    }
marci@552
    39
    std::cout << std::endl;
marci@552
    40
  }
marci@549
    41
marci@549
    42
  return 0;
marci@549
    43
}