Sort
Usage
• Sort[list] 以规范顺序对 list 中元素排序.
• Sort[list, p] 使用排序函数p对 list 中元素排序.
Notes
• Mathematica 所使用的规范顺序的详细描述参见 A.3.9节. • Sort[list, p] 把函数 p 应用到 list 中的元素对上以确定它们是否是按顺序排列的. 缺省的函数 p 为 OrderedQ[{#1, #2}]&. • Sort 可被使用到带任意头(不单是 List)的表达式上.
Further Examples
You can put a list of letters into canonical order.
In[1]:=
|
Out[1]=
|
Both of these commands sort the list from largest to smallest.
In[2]:=
|
Out[2]=
|
In[3]:=
|
Out[3]=
|
This puts elements that do not depend on x before those that do.
In[4]:=
|
Out[4]=
|
Here are two numbers.
In[5]:=
|
In[6]:=
|
In the canonical order x comes before y.
In[7]:=
|
Out[7]=
|
However, x is greater than y in magnitude.
In[8]:=
|
Out[8]=
|
Ordering numeric expressions according to magnitude by default would usually be too slow. This is why the following differ.
In[9]:=
|
Out[9]=
|
In[10]:=
|
Out[10]=
|
In[11]:=
|
|