<A NAME=SORT>
<TITLE>SORT</TITLE></A>
<b><a href=r37_idx.html>INDEX</a></b><p><p>
<B>SORT</B> _ _ _ _ _ _ _ _ _ _ _ _ <B>operator</B><P>
<P>
<P>
<P>
The <em>sort</em> operator sorts the elements of a list according to
an arbitrary comparison operator.
<P> <H3>
syntax: </H3>
<P>
<P>
<em>sort</em>(<lst>,<comp>)
<P>
<P>
<P>
<lst> is a
<A HREF=r37_0053.html>list</A> of algebraic expressions.
<comp> is a comparison operator which defines a partial
ordering among the members of <lst>. <comp> may be
one of the builtin comparison operators like
<em><</em>(
<A HREF=r37_0115.html>lessp</A>), <em><=</em>(
<A HREF=r37_0114.html>leq</A>)
etc., or <comp> may be the name of a comparison procedure.
Such a procedure has two arguments, and it returns
<A HREF=r37_0122.html>true</A> if the first argument
ranges before the second one, and 0 or
<A HREF=r37_0014.html>nil</A> otherwise.
The result of <em>sort</em> is a new list which contains the
elements of <lst> in a sequence corresponding to <comp>.
<P> <H3>
examples: </H3>
<P><PRE><TT>
procedure ce(a,b);
if evenp a and not evenp b then 1 else 0;
for i:=1:10 collect random(50)$
sort(ws,>=);
{41,38,33,30,28,25,20,17,8,5}
sort(ws,<);
{5,8,17,20,25,28,30,33,38,41}
sort(ws,ce);
{8,20,28,30,38,5,17,25,33,41}
procedure cd(a,b);
if deg(a,x)>deg(b,x) then 1 else
if deg(a,x)<deg(b,x) then 0 else
if deg(a,y)>deg(b,y) then 1 else 0;
sort({x^2,y^2,x*y},cd);
2 2
{x ,x*y,y }
</TT></PRE><P><P>
<P>