Script Name: SelectionSort
Script Description Sorts alphabetic & "integer" strings
Author: Dual (http://soldatcentral.com/index.php?page=profile&u=57)
Hosted by: Soldat Central - http://soldatcentral.com/ (http://soldatcentral.com/)
Core Version: 2.6.3
Compile Test: (http://soldatcentral.com/images/pass.gif) Passed
SelectionSort() 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.
(http://soldatcentral.com/images/download.gif) (http://soldatcentral.com/dl.php?id=103&act=1)
(Size 755 B)
- http://soldatcentral.com/index.php?page=script&f=103 -
** Script hosted by Soldat Central (http://soldatcentral.com/index.php?page=script&f=103)! Please visit the author's script page (http://soldatcentral.com/index.php?page=script&f=103) and Rate this script **