home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / diverses / leda / src / graph_al / _dfsnum.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-15  |  1.6 KB  |  59 lines

  1. /*******************************************************************************
  2. +
  3. +  LEDA  2.1.1                                                 11-15-1991
  4. +
  5. +
  6. +  _dfsnum.c
  7. +
  8. +
  9. +  Copyright (c) 1991  by  Max-Planck-Institut fuer Informatik
  10. +  Im Stadtwald, 6600 Saarbruecken, FRG     
  11. +  All rights reserved.
  12. *******************************************************************************/
  13.  
  14.  
  15.  
  16. /*******************************************************************************
  17. *                                                                              *
  18. *  DFS_NUM (depth first search numbering)                                      *
  19. *                                                                              *
  20. *******************************************************************************/
  21.  
  22.  
  23. #include <LEDA/graph_alg.h>
  24.  
  25. int dfs_count1,dfs_count2;
  26.  
  27. void d_f_s(node v, node_array(bool)& S, node_array(int)& dfsnum, 
  28.                                         node_array(int)& compnum,
  29.                                         list(edge)& T )
  30. { node w;
  31.   edge e;
  32.  
  33.   S[v] = true;
  34.   dfsnum[v] = ++dfs_count1;
  35.  
  36.   forall_adj_edges(e,v) 
  37.     { w = target(e);
  38.       if (!S[w]) 
  39.        { T.append(e);
  40.          d_f_s(w,S,dfsnum,compnum,T);
  41.         }
  42.      }
  43.  
  44.   compnum[v] = ++dfs_count2;
  45.  
  46. list(edge) DFS_NUM(const graph& G, node_array(int)& dfsnum, 
  47.                                    node_array(int)& compnum)
  48.   list(edge) T;
  49.   node_array(bool) reached(G,false);
  50.   node v;
  51.   dfs_count1 = dfs_count2 = 0;
  52.   forall_nodes(v,G) if (!reached[v]) d_f_s(v,reached,dfsnum,compnum,T);
  53.   return T;
  54. }
  55.  
  56.