Next: , Previous: , Up: dynamic arrays   [Index]


40.10 Sorting dynamic arrays

The following syntactic bindings are exported by the library (vicare containers dynamic-arrays sort). The syntactic bindings whose name is prefixed with $ are unsafe operations: they do not validate their arguments before accessing them.

Function: dynamic-array-sort item< arry
Function: $dynamic-array-sort item< arry

Build and return a new dynamic array holding all the objects from arry sorted from the lesser to the greater according to the comparison procedure item<.

item< must be a procedure accepting two objects from arry and returning true if the first argument is less than the second argument.

(let* ((C1 (dynamic-array 0 4 3 1 2 5))
       (C2 (dynamic-array-sort < C1)))
  (dynamic-array->list C2))
⇒ (0 1 2 3 4 5)
Function: dynamic-array-sort! item< arry
Function: $dynamic-array-sort! item< arry

Sort all the objects from arry from the lesser to the greater according to the comparison procedure item<; arry itself is mutated and returned.

item< must be a procedure accepting two objects from arry and returning true if the first argument is less than the second argument.

(let ((C (dynamic-array 0 4 3 1 2 5)))
  (dynamic-array->list (dynamic-array-sort! < C)))
⇒ (0 1 2 3 4 5)