Skip to content

Modern LinkedList SortList

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

Home › LinkedList › LinkedList › SortList

SortList

Sorts a LinkedList in ascending order by relinking nodes; equal elements keep order.

Syntax

SortList( l )

Notes

  • ascending, by '<' on T

Examples

#import "std/containers"
using containers

dim q as LinkedList( of int32 )
q.PushBack( 5 ) : q.PushBack( 1 ) : q.PushBack( 4 )

SortList( q )            '' ascending, by T's own '<'
for each v in q
    print v;
next
print                    '' 1 4 5

'' There is ONE list sort and it is the stable one: introsort needs
'' random access for its pivot and to scan inward from both ends, and a
'' linked list gives neither. So this is a bottom-up merge sort that
'' relinks nodes -- no elements are moved.

Library: LinkedList
Category: LinkedList
Documented under: Sorting

Clone this wiki locally