function [sortedOut, org_index_r, org_index_c] =sort_left(matrix, cross)

if any(cross <0)
    rowSum = sum(matrix == -1,2);
    [~,org_index_r] = sort(rowSum,'descend');
    matrix=matrix((org_index_r),:);
    
    columnSum=sum(matrix == -1);
    [~, org_index_c]=sort(columnSum, 'descend');
    sortedOut=matrix(:,(org_index_c));
else
    rowSum = sum(matrix == 1,2);
    [~,org_index_r] = sort(rowSum,'descend');
    matrix=matrix((org_index_r),:);
    
    columnSum=sum(matrix == 1);
    [~, org_index_c]=sort(columnSum, 'descend');
    sortedOut=matrix(:,(org_index_c));   
    
end

end