   function [p] = bfs(A,init )
%% function [p] = bfs(A,init)
%% queue implementation
%%--------------------- enqueue first node
 p=[init];
 n = size(A,1);
 mark = zeros(n,1);
 mark(init) = 1;
%%-------------------- all nodes must be visited
for h=1:n 
%%-------------------- scan nodes in adj(p(h))
    [ii, jj, rr] = find(A(:,p(h)));
    for v=ii'  
        if (mark(v)==0)
%%-------------------- add v to queue and mark it  
          p = [p, v] ; 
          mark(v) = 1;
        end
    end
end




