Post Reply 
How to sort two lists? Sort distance
12-03-2019, 07:30 PM (This post was last modified: 12-06-2019 09:35 PM by StephenG1CMZ.)
Post: #19
RE: How to sort two lists?
Here is a version that works with your choice of sort (distance) function as a parameter:

Code:

 EXPORT MYSORTFUN(LST,ITEM)
 //EXAMPLE DISTANCE FUNCTION: USE YOUR OWN
 BEGIN
  RETURN ABS(LST-ITEM);
 END;

 EXPORT SortByFun(LST,SortFun)
 //Sort using SortFun as your sort function
 //EG SortByFun(LST,MYDIST)
 BEGIN
  LOCAL SORTORDER:=SortFun;
  LOCAL SORTED:=Sortn({LST,SORTORDER},2);
  RETURN SORTED(1); //TO SEE THE SORT ORDER:2
 END;

 EXPORT SORTER()
 //EXAMPLE
 BEGIN
  LOCAL TESTLST:={10,20,5};
  LOCAL ITEM:=10;
  RETURN SortByFun(TESTLST,MYSORTFUN(TESTLST,ITEM));  
 END;

SortByFun has now been added to my collection of sort routines:
https://www.hpmuseum.org/forum/thread-11...#pid124491

Ailoher, did you have any specific sort distance function in mind? Or is ABS(LST-Item) OK?

Stephen Lewkowicz (G1CMZ)
https://my.numworks.com/python/steveg1cmz
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: How to sort two lists? - parisse - 04-29-2016, 07:33 PM
RE: How to sort two lists? - primer - 04-29-2016, 09:22 PM
RE: How to sort two lists? - StephenG1CMZ - 04-30-2016, 10:04 AM
RE: How to sort two lists? - parisse - 05-02-2016, 05:44 AM
RE: How to sort two lists? - Tyann - 05-02-2016, 05:32 AM
RE: How to sort two lists? - Tyann - 05-02-2016, 10:35 AM
RE: How to sort two lists? - Tyann - 05-02-2016, 05:10 PM
RE: How to sort two lists? - DrD - 05-02-2016, 11:11 AM
RE: How to sort two lists? - StephenG1CMZ - 05-02-2016, 12:11 PM
RE: How to sort two lists? - ailoher - 12-03-2019, 10:24 AM
RE: How to sort two lists? - StephenG1CMZ - 12-03-2019, 04:43 PM
RE: How to sort two lists? - Albert Chan - 12-03-2019, 06:00 PM
RE: How to sort two lists? - StephenG1CMZ - 12-03-2019 07:30 PM
RE: How to sort two lists? - ailoher - 12-05-2019, 06:55 PM
RE: How to sort two lists? - StephenG1CMZ - 12-06-2019, 12:30 AM



User(s) browsing this thread: 1 Guest(s)