function [L,R] = sweep (N,L,R,S,ntotalA,ntotalB)

for j = N/2:N-3
    G = superblock (L(j-1),S(j),S(j+1),R(N-j-1),ntotalA,ntotalB);
    L(j) = getleft (L(j-1),S(j),S(j+1),R(N-j-1),G);
end;

for j = N-2:-1:3
    G = superblock (L(j-1),S(j),S(j+1),R(N-j-1),ntotalA,ntotalB);
    R(N-j) = getright (L(j-1),S(j),S(j+1),R(N-j-1),G);
end;

for j = 2:N/2-1
    G = superblock (L(j-1),S(j),S(j+1),R(N-j-1),ntotalA,ntotalB);
    L(j) = getleft (L(j-1),S(j),S(j+1),R(N-j-1),G);
end;
