Sorting algorithms/Insertion sort: Difference between revisions

Content added Content deleted
Line 954: Line 954:
If the elements of the array may be of linear type, then it becomes necessary to compare the elements by reference. Furthermore it is necessary to break down the array's view, to obtain views of the elements to be compared. Here, as in the simpler implementation for non-linear elements, I use '''array_subcirculate''' to insert an element into its correct position.
If the elements of the array may be of linear type, then it becomes necessary to compare the elements by reference. Furthermore it is necessary to break down the array's view, to obtain views of the elements to be compared. Here, as in the simpler implementation for non-linear elements, I use '''array_subcirculate''' to insert an element into its correct position.


(The complications are necessary to prevent us accidentally having two copies of a linear value.)
(The complications are necessary to prevent us accidentally having two copies of a linear value. Having two copies would introduce such nasty possibilities as a double-free error, use of a destroyed list, etc.)


<lang ATS>#include "share/atspre_staload.hats"
<lang ATS>#include "share/atspre_staload.hats"