function C = Crossover(M)
% C = Crossover(M)
%This program is the crossover operator of a simple genetic algorithm that
%uses a single point crossover. The input matrix M (mating pool) has rows
%consisting of the current population's mating pool, assumed even in
%number, and given in binary code. For each adjacent pair of rows 2i-1,
%and 2i, a random point of splicing is selected (between 1 and k-1, where k
%is the length of the string), and the tails of the two strings are
%interchanged after this splice point. The resulting two strings represent
%the corresponding two offspring to be placed in the corresponding rows of
%the output matrix M.
[n s] = size(M);
for i=1:n/2
c = ceil((s-1)*rand);
C(2*i-1,:)=[M(2*i-1,1:c) M(2*i,(c+1):s)];
C(2*i,:) =[M(2*i,1:c) M(2*i-1,(c+1):s)];
end