Skip to content

Modern LinkedList SortListBy

Paul Squires edited this page Oct 19, 2026 · 5 revisions

Home › LinkedList › LinkedList › SortListBy

SortListBy

Sorts a LinkedList by your comparer, relinking nodes; equal elements keep order.

Syntax

SortListBy( l, less )

Notes

  • ascending, by a comparer

Examples

#import "std/containers"
using containers

dim q as LinkedList( of ustring )
q.PushBack( "pear" ) : q.PushBack( "fig" ) : q.PushBack( "banana" )

'' Sort by length, with a caller-supplied strict '<'
SortListBy( q, function( byref x as ustring, byref y as ustring ) as boolean
    return len( x ) < len( y )
end function )

for each v in q
    print v
next                     '' fig / pear / banana

'' Stable, so equal-length names would keep their original order

Library: LinkedList
Category: LinkedList
Documented under: Sorting

Clone this wiki locally