Skip to content

Modern Array RemoveSwap

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

Home › Array › Array Container › RemoveSwap

RemoveSwap

Removes the element at a position quickly by moving the last element into its place.

Syntax

RemoveSwap( byval i as int32 )

Notes

  • O(1) — does NOT preserve order

Examples

#import "std/containers"
using containers

dim v as Array( of ustring )
v.Push( "a" ) : v.Push( "b" ) : v.Push( "c" ) : v.Push( "d" )

'' O(1), but the LAST element moves into the hole -- order is not preserved.
'' Named so it cannot be picked by accident.
v.RemoveSwap( 0 )
print v[ 0 ] & v[ 1 ] & v[ 2 ]     '' dbc
print v.Count            '' 3

Library: Array Container
Category: Array
Documented under: Members

Clone this wiki locally