Question: Please help me BFS Code

Please help me BFS Code. Why am I wrong?

 

BFS := proc(G::Graph, x1)

local A, B, C, S, T, x, y;  A := [x1];  T := Graph(x1); 

B := { op(Vertices(G)) };  B := B minus {x1};  S := { };

while not (B = []) do

          x := A[1];

          C := { op(Neighbors(G, x) ) } intersect B;   B := B minus C;

          for y in C do

                    T := AddVertex( T, y);  T := AddEdge( T, {x, y});  end do;

          S := S union C;  A := A minus {x};

          if A = { } then A := A union S  end if;

          S := { };  C := { };

end do;

return T;

end proc;

Please Wait...