Script Name: InsertionSort
Script Description: Easiest and fastest way to sort small amout of nearly sorted data set.
Original Author(s): Savage
Compilation: Passed
Core Version: 2.8.0 (SC3)
Ascending
procedure InsertionSortAsc(var List: array of Integer);
var
temp,i,j: Integer;
begin
for i := 1 to high(List) do
for j := i downto 1 do
if List[j-1]>List[j] then begin
temp := List[j-1];
List[j-1] := List[j];
List[j] := temp;
end else
break;
end;
Descending
procedure InsertionSortDes(var List: array of Integer);
var
temp,i,j: Integer;
begin
for i := 1 to high(List) do
for j := i downto 1 do
if List[j-1]<List[j] then begin
temp := List[j-1];
List[j-1] := List[j];
List[j] := temp;
end else
break;
end;