Author Topic: InsertionSort  (Read 2706 times)

0 Members and 1 Guest are viewing this topic.

Offline Savage

  • Soldier
  • **
  • Posts: 155
InsertionSort
« on: April 25, 2015, 07:42:14 am »
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
Code: [Select]
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
Code: [Select]
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;
« Last Edit: March 07, 2016, 05:01:56 pm by Savage »