forked from DonovanChan/fmfunctions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathListSortDesc.calc
53 lines (44 loc) · 1.54 KB
/
ListSortDesc.calc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
Case(
// One value left in list - return just that value
ValueCount( theList ) <= 1;
GetValue (theList; 1 );
// Default
Let(
[
// split list in two
length = ValueCount( theList );
leftLength = Floor( length / 2 );
rightLength = length - leftLength;
leftList = LeftValues( theList; leftLength);
rightList = RightValues( theList; rightLength);
// sort each sub-list
sortedLeft = ListSortDesc( leftList );
sortedRight = ListSortDesc( rightList );
// merge the two sorted lists
mergedList = ListSortDescLoop( sortedLeft; sortedRight )
];
ListTrimCR ( mergedList )
)
)
/* —————————————————————————————— //
NAME:
ListSortDesc( theList )
v1.1
PURPOSE:
Sort a return-delimited list descending using the “mergesort” algorithm
HISTORY:
Created by Soliant Consulting (See below or FM 8 Functions p. 228)
Modified 2008.06.17 by DChandler for formatting/commenting preference
Modified 2010.10.29 by DChandler for descending order
Modified 2010.11.10 by DChandler to trim trailing carriage return
INPUT:
theList: return-delimited list of values
OUTPUT:
The same list, sorted ascending
DEPENDENCIES:
Custom Functions: ListSortLoop(), ListTrimCR()
Function created by Soliant Consulting
www.soliantconsulting.com
Released under the Creative Commons Attribution 2.5 License
http://creativecommons.org/licenses/by/2.5/
*/