   function [p, ptr, mask] = bfsWithLev(A,init)
%% function [p, ptr, mask] = bfsWithLev(A,init)  
%% standard BFS traversal- not CMK ordering.
%% queue implementation- outputs level pointer
%% level l consists of entries ptr[l]--ptr[l+1]-1
%% in permutation p 
 p=[init];
 len = 1;
 n = size(A,1);
 mask = zeros(n,1); 
 mask(init) = 1; 
%%
 klev = 1;
 for k=1:n
     h = p(k); 
%%-------------------- scan points in adj(j)
     [ii, jj, rr] = find(A(:,h));
     ll = mask(h)+1;
     %%--------------------unmarked n. neighbors of p(k)
     for l = 1:length(ii);
       j = ii(l);
       if (mask(j)==0) 
	 len    = len+1;
	 p(len) = j;
         mask(j) = ll;
       end
     end
%%-------------------- set-up pointer array for levs
     if (ll> klev)
       ptr(klev) = k;
       klev = ll;
     end
 end
 %% 
 ptr(klev) = n+1;
