日期:2011-12-12  浏览次数:20678 次

  1. <?php 
  2.     //调用 
  3.     require 'alGraph.php'; 
  4.     $a = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'); 
  5.     $b = array('ab', 'bc', 'be', 'cd', 'df', 'fg', 'gh', 'ga', 'hj', 'gi'); 
  6.  
  7.     $test = new ALGraph($a, $b); 
  8.     print_r($test->bfs()); 
  9. ?> 
  10. alGraph.php 
  11. <?php 
  12.     //顶点类 
  13.     class Vex{ 
  14.         private $data; 
  15.         private $headLink; 
  16.  
  17.         public function Vex($data, $headLink = NULL){ 
  18.             $this->data = $data; 
  19.             $this->headLink = $headLink; 
  20.         } 
  21.  
  22.         public function getData(){ 
  23.