function e = replaceEdgeEnd( e, v1, v2 )
%e = replaceVertex( e, v1, v2 )
%   e contains a pair of vertexes.  v1 is assumed to equal one element of e.
%   Its occurrence is replaced by v2, and the result is sorted.  All other
%   elements of e are undisturbed.

% fprintf( 1, 'replaceEdgeEnd [ %d, %d ]  %d -> %d\n', e(1:2), v1, v2 );

    if e(1)==v1
        if (v2 <= e(2)) || (e(2)==0)
            e(1) = v2;
        else
            e(1:2) = [ e(2), v2 ];
        end
    else
        if v2 >= e(1)
            e(2) = v2;
        else
            e(1:2) = [ v2, e(1) ];
        end
    end

% fprintf( 1, 'replaceEdgeEnd [ %d, %d ]\n', e(1:2) );
end
