Sorting algorithms/Insertion sort: Difference between revisions

Content added Content deleted
Line 329: Line 329:
Output:
Output:
<pre>[2, 4, 11, 17, 19, 24, 25, 28, 44, 46]</pre>
<pre>[2, 4, 11, 17, 19, 24, 25, 28, 44, 46]</pre>

=={{header|Delphi}}==

<lang Delphi>procedure InsertionSort(var S: string);
var
I, J, L: Integer;
Ch: Char;

begin
L:= Length(S);
for I:= 2 to L do begin
Ch:= S[I];
J:= I - 1;
while (J > 0) and (S[J] > Ch) do begin
S[J + 1]:= S[J];
Dec(J);
end;
S[J + 1]:= Ch;
end;
end;
</lang>
<pre>
// in : S = 'the quick brown fox jumps over the lazy dog'
// out: S = ' abcdeeefghhijklmnoooopqrrsttuuvwxyz'
</pre>


=={{header|E}}==
=={{header|E}}==