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

  1. /*******************************************************************************
  2. +
  3. +  LEDA  2.1.1                                                 11-15-1991
  4. +
  5. +
  6. +  _bfs.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. *  BFS  (breadth first search)                                                 *
  19. *                                                                              *
  20. *******************************************************************************/
  21.  
  22.  
  23.  
  24. #include <LEDA/graph_alg.h>
  25.  
  26. list(node) BFS(const graph&, node s, node_array(int)& dist)
  27.   list(node) Q(s);
  28.   node v,w;
  29.   list_item it;
  30.  
  31.   dist[s] = 0;
  32.   it = Q.first();
  33.  
  34.   while (it != nil)
  35.     { v = Q[it];
  36.       forall_adj_nodes(w,v)
  37.          if (dist[w] < 0) { Q.append(w); 
  38.                             dist[w] = dist[v]+1;
  39.                            }
  40.       it = Q.succ(it);
  41.      }
  42.   return Q;
  43. }
  44.  
  45.