src/work/bfsdemo.cc
changeset 4 8009bb5ddd09
parent 3 272a5677bd6d
child 6 b63d1bc367f7
     1.1 --- a/src/work/bfsdemo.cc	Sat Dec 13 15:44:50 2003 +0000
     1.2 +++ b/src/work/bfsdemo.cc	Sun Dec 14 15:32:46 2003 +0000
     1.3 @@ -24,6 +24,9 @@
     1.4      NodeType *operator ->() const { return &(G->nodes[n]);}
     1.5      bool isValid() const {return n<=5000;}
     1.6      int Index() {return n;} //csak a kiirashoz kell
     1.7 +
     1.8 +    NodeIterator() {}
     1.9 +    NodeIterator(IGraph &Gr) {G=&Gr;n=1;} //Bfs class prefer this.
    1.10    };
    1.11    
    1.12    void GetFirst(NodeIterator &i) {i.G=this;i.n=1;}
    1.13 @@ -40,6 +43,10 @@
    1.14      NodeIterator To() const {NodeIterator i; i.G=G;i.n=t;return i;}
    1.15      NodeIterator Anode() const {return From();}
    1.16      NodeIterator Bnode() const {return To();}
    1.17 +
    1.18 +    OutEdgeIterator() {}
    1.19 +    OutEdgeIterator(IGraph &Gr,NodeIterator &n)  //Bfs class prefer this.
    1.20 +    {G=&Gr;f=n.n;t=0;operator++();}
    1.21    };
    1.22  
    1.23    typedef OutEdgeIterator EdgeIterator;
    1.24 @@ -70,14 +77,48 @@
    1.25    do_nothing_map priority; //node->int (W)
    1.26  };
    1.27  
    1.28 +// New style bfs traits
    1.29 +class BFS_T 
    1.30 +{
    1.31 +public:
    1.32 +
    1.33 +  typedef IGraph Graph_t;
    1.34 +  typedef IGraph::OutEdgeIterator SearchEdgeIterator;
    1.35 +  
    1.36 +  struct visited_map_t {
    1.37 +    typedef bool value_type;
    1.38 +    void Put(const IGraph::NodeIterator &n,const value_type &t) { n->isVis=t; }
    1.39 +    value_type Get(const IGraph::NodeIterator &n) const { return n->isVis; }
    1.40 +  };
    1.41 +  struct tree_map_t {
    1.42 +    typedef IGraph::EdgeIterator value_type;
    1.43 +    void Put(const IGraph::NodeIterator &n,const value_type &t)
    1.44 +    { cout << t.From().Index() << "->" << t.To().Index() << '\n'; }
    1.45 +  };
    1.46 +  typedef do_nothing_map dist_map_t;   //node->int (W)
    1.47 +  typedef do_nothing_map priority_map_t; //node->int (W)
    1.48 +};
    1.49 +
    1.50  
    1.51  int main()
    1.52  {
    1.53    IGraph IG;
    1.54 -  IMaps_t IMaps;
    1.55  
    1.56 +//   //Function-syte calling
    1.57 +//   IMaps_t IMaps;
    1.58 +
    1.59 +//   IGraph::NodeIterator in;
    1.60 +//   IG.GetFirst(in);
    1.61 +//   ++in;
    1.62 +//   bfs_fn(IG,in,IMaps);  
    1.63 +
    1.64 +  //Class-style calling:
    1.65 +  
    1.66    IGraph::NodeIterator in;
    1.67    IG.GetFirst(in);
    1.68    ++in;
    1.69 -  bfs(IG,in,IMaps);  
    1.70 +  Bfs<BFS_T> bfs;
    1.71 +  bfs.SetG(IG);
    1.72 +  bfs.Init(in);
    1.73 +  bfs.Run();
    1.74  }