Пример #1
0
 function breadthFirstSearch($startVertex)
 {
     $startVertex->visited = true;
     $Q = new SplQueue();
     $Q->push($startVertex);
     while (!$Q->empty()) {
         $x = new Vertex();
         $x = $Q->front();
         $Q->pop();
         foreach ($x->neighbors as $VertexPtr) {
             if ($VertexPtr->visited == false) {
                 $VertexPtr->visited = trie;
                 $VertexPtr->pred = $x;
                 $Q->push($VertexPtr);
             }
         }
     }
 }