Skip to content

Modern Sorting IsSorted

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

Home › Sorting › Sorting › IsSorted

IsSorted

Returns true if the Array is already in ascending order.

Syntax

IsSorted( a ) as boolean

Examples

#import "std/containers"
using containers

dim v as Array( of int32 )
v.Push( 1 ) : v.Push( 2 ) : v.Push( 2 ) : v.Push( 3 )

print IsSorted( v )          '' true -- equal neighbours are still sorted

v.Push( 0 )
print IsSorted( v )          '' false

'' O(n) and allocation-free, so it is cheap as a guard before a sort
'' that is usually redundant
if not IsSorted( v ) then Sort( v )
print IsSorted( v )          '' true

Library: Sorting
Category: Sorting
Documented under: Procedures

Clone this wiki locally