function [ index1,index2 ] = hadsorts( n )
%UNTITLED2 Summary of this function goes here
%   Detailed explanation goes here
N=pow2(n);
k1=N; k2=1; k3=N/2;
ind=1;
for i1=1:log2(N)
    L1=1;
    for i2=1:k2
        for i3=1:k3
            i=i3+L1-1; j=i+k3;
            index1(ind)=i;
            index2(ind)=j;
            ind=ind+1;
        end
            L1=L1+k1;
    end
        k1 = k1/2;  k2 = k2*2;  k3 = k3/2;
end


end

