Sorting algorithms/Insertion sort: Difference between revisions

Added entry for Eiffel.
(Added entry for Eiffel.)
Line 325:
> a
# value: [10, 10, 10, 13, 14, 17, 22, 23, 24, 26, 27, 27, 39, 40, 47, 50, 52, 53, 54, 55, 59, 60, 61, 62, 63, 65, 67, 71, 75, 75, 78, 83, 85, 85, 88, 91, 93, 94, 96, 99].diverge()</lang>
 
=={{header|Eiffel}}==
 
This solution is shown in the routine <code lang="eiffel">sort</code> of the class <code lang="eiffel">MY_SORTED_SET</code>.
 
For a more complete explanation of the Eiffel sort examples, see the [[Sorting algorithms/Bubble sort#Eiffel|Bubble sort]].
 
<lang eiffel>class
MY_SORTED_SET [G -> COMPARABLE]
inherit
TWO_WAY_SORTED_SET [G]
redefine
sort
end
create
make
 
feature
sort
-- Insertion sort
local
l_j: INTEGER
l_value: like item
do
across 2 |..| count as ii loop
from
l_j := ii.item - 1
l_value := Current.i_th (ii.item)
until
l_j < 1 or Current.i_th (l_j) <= l_value
loop
Current.i_th (l_j + 1) := Current.i_th (l_j)
l_j := l_j - 1
end
Current.i_th (l_j + 1) := l_value
end
end
 
end</lang>
 
=={{header|Emacs Lisp}}==