({{, (RefLink[ReverseSort, paclet:ref/ReverseSort])[list] 
sorts the elements of list into reverse canonical order. }, {, (RefLink[ReverseSort, paclet:ref/ReverseSort])[list,p]
sorts using the ordering function p. }})

OpenersNotesSection(Spacer1)Details

(RefLink[ReverseSort, paclet:ref/ReverseSort]) by default orders integers and rational and approximate real numbers by their numerical values, sorting from largest to smallest.

(RefLink[ReverseSort, paclet:ref/ReverseSort]) gives the same result as reversing (RefLink[Sort, paclet:ref/Sort]) except it does not reverse ties.

(RefLink[ReverseSort, paclet:ref/ReverseSort])[list,p] applies the function p to pairs of elements in list to determine whether they are in order. The default function p is (RefLink[Order, paclet:ref/Order]).

(RefLink[ReverseSort, paclet:ref/ReverseSort]) can be used on expressions with any head, not only (RefLink[List, paclet:ref/List]).

OpenersPrimaryExamplesSection(Spacer1)Examples  (10)

OpenersExampleSection0(Spacer1)Basic Examples  (2)

Sort a list in reverse canonical order:

ReverseSort[{c,b,d,a}]

Sort a list using an ordering function:

ReverseSort[{"cat","fish","catfish","Cat"},AlphabeticOrder["English"]]

OpenersExampleSection1(Spacer1)Scope  (4)

Sort a list of integers in reverse order:

ReverseSort[{0,11,13,4,9}]

Reverse-sort an expression with any head:

ReverseSort[head[x,z,y,t]]

(RefLink[ReverseSort, paclet:ref/ReverseSort]) works with associations:

ReverseSort[<|a->4,b->1,c->3,d->2,e->2|>]

Use an ordering function as second argument:

ReverseSort[{0,11,13,4,9},Greater]

Use a pure function as ordering function:

ReverseSort[{c,b,d,a},OrderedQ[{#1,#2}]&]

OpenersExampleSection3(Spacer1)Properties & Relations  (4)

(RefLink[ReverseSort, paclet:ref/ReverseSort]) gives the same result as reversing (RefLink[Sort, paclet:ref/Sort]) except it does not reverse ties:

list={x,z,y}

ReverseSort[list]

%===Reverse[Sort[list]]

(RefLink[NumericalOrder, paclet:ref/NumericalOrder]) treats 3 and 3.`10 as a tie:

NumericalOrder[3,3.`10]

Both (RefLink[ReverseSort, paclet:ref/ReverseSort]) and (RefLink[Sort, paclet:ref/Sort]) do not reorder ties:

list={2,3,3.`10,5};

list1=ReverseSort[list,NumericalOrder]

list2=Sort[list,NumericalOrder]

Therefore, those two results are not the reverse of one another:

list1===Reverse[list2]

(RefLink[ReverseSort, paclet:ref/ReverseSort]) with an ordering function p is equivalent to (RefLink[Sort, paclet:ref/Sort]) with the reverse ordering function:

list={2,3,3.`10,5};

The reverse ordering for (RefLink[LessEqual, paclet:ref/LessEqual]) is provided by (RefLink[Greater, paclet:ref/Greater]):

Not[LessEqual[a,b]]

Sort[list,LessEqual]

ReverseSort[list,Greater]

For ordering functions returning -1, 0, 1, the reverse ordering is obtained composing with (RefLink[Minus, paclet:ref/Minus]):

list={"B","D","A","C"};

Sort[list,AlphabeticOrder[]]

ReverseSort[list,Composition[Minus,AlphabeticOrder]]

(RefLink[ReverseSort, paclet:ref/ReverseSort]) orders a list of pairs of numbers by decreasing the first element:

pairs=RandomInteger[10,{5,2}]

ReverseSort[pairs]

Use (RefLink[ReverseSortBy, paclet:ref/ReverseSortBy]) to select which element is sorted in decreasing order:

ReverseSortBy[pairs,First]

ReverseSortBy[pairs,Last]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[Sort, paclet:ref/Sort])  ▪  (RefLink[ReverseSortBy, paclet:ref/ReverseSortBy])  ▪  (RefLink[NumericalSort, paclet:ref/NumericalSort])  ▪  (RefLink[AlphabeticSort, paclet:ref/AlphabeticSort])  ▪  (RefLink[Ordering, paclet:ref/Ordering])  ▪  (RefLink[Order, paclet:ref/Order])  ▪  (RefLink[OrderedQ, paclet:ref/OrderedQ])  ▪  (RefLink[Reverse, paclet:ref/Reverse])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Rearranging & Restructuring Lists, paclet:guide/RearrangingAndRestructuringLists])}})}})