Script Name: SelectionSort
Script Description Sorts alphabetic & "integer" strings
Author: DualHosted by: Soldat Central - http://soldatcentral.com/Core Version: 2.6.3
Compile Test: PassedSelectionSort() allows you to arrange a string array representing alphabetic characters (including special characters) in alphabetical order,
as well as a string array representing integer literals. Integer values will be sorted by greatness.
procedure ZeroFill(var S: string; Count: integer);
var
i: integer;
begin
for i:= 1 to Count do
begin
S:= '0' + S;
end;
end;
function SelectionSort(var AOS: array of string; Index: integer; Ival: boolean): integer;
var
b, c1, c2: string;
i, j, m: integer;
begin
for i:= 0 to Index do
begin
if (length(AOS[i]) > m) then
begin
m:= length(AOS[i]);
end;
end;
i:= 1;
while (j < Index) do
begin
c1:= AOS[j];
c2:= AOS[j + i];
if (Ival) then
begin
ZeroFill(c1, m - length(c1));
ZeroFill(c2, m - length(c2));
end;
if (c1 < c2) then
begin
b:= AOS[j];
AOS[j]:= AOS[j + i];
AOS[j + i]:= b;
Inc(Result, 1);
end;
if (j + i < Index) then
begin
Inc(i, 1);
end else
begin
i:= 1;
Inc(j, 1);
end;
end;
end;
Parameters:AOS: array of string
String array to be sorted.
Index: integer
Assigns an array index which determines the sort extent.
If you want to sort the whole array pass the highest array index on it.
Ival: boolean
Only enable this if you want to sort an array representing integer values.
Return Value:SelectionSort() returns the amount of interchanges which were required to sort the array.
It also returns the sorted array in terms of a reference.
Note:Always disable
Ival if you sort strings by alphabetic characters otherwise SelectionSort() won\'t work properly.