custom sorting of lists ?
    Codifies 
    a at b.com
       
    Fri Oct 12 19:40:28 UTC 2018
    
    
  
a while ago I wrote a doubly linked list (in C), which has a 
compare callback to allow custom sorting for example
int cmpNodes(cnode_t* n1, cnode_t* n2)
{
   mapNode_t* rn1 = (mapNode_t*)(n1->data);
   mapNode_t* rn2 = (mapNode_t*)(n2->data);
   if (rn1->G + rn1->H > rn2->G + rn2->H) return 1;
   return 0;
}
would be called by
clistSort(openList, cmpNodes);
The list would then be ordered by G + H fields (or any other 
algorithm you code)
I notice there is a doubly linked list in the standard library, 
however it doesn't seem to allow for a custom compare, I'd rather 
not port my old C list code, can someone please give me some 
clues as to how I can reorder a list with a custom comparison...?
    
    
More information about the Digitalmars-d-learn
mailing list