0 Members and 1 Guest are viewing this topic.
procedure ActivateServer();var Str1, Str2: string;begin Str1:= '28950'; Str2:= '500'; if (Str1 > Str2) then begin WriteLn(Str1 + ' is greater than ' + Str2); end else begin WriteLn(Str2 + ' is greater than ' + Str1 + ', really??'); end;end;
strtoint...
Owing to this problem my QuickSort procedures are divided into two seperate ones.
Or you could write a quick thing to compare them based on the actual chars in the string (would be reflexive but easy to do).
I thought about filling the compare string which is less in length with zeros, so both strings are equal in length.
function GetLongestString(var Str: array of string): integer;var i: integer;begin for i:= 0 to ArrayHigh(Str) do begin if (length(Str[i]) > length(Str[Result])) then begin Result:= i; end; end;end;function FillWith(const Filler: char; Amount: integer): string;var i: integer;begin for i:= 1 to Amount do begin Result:= Filler + Result; end;end;procedure SelectionSort(var Field: array of string; Left, Right: integer);var Buffer: string; i, j, m: integer;begin i:= 1; m:= GetLongestString(Field); while (j < Right) do begin Field[j]:= FillWith('0', m - length(Field[j])); Field[j + i]:= FillWith('0', m - length(Field[j + i])); if (Field[j] > Field[j + i]) then begin Buffer:= Field[j]; Field[j]:= Field[j + i]; Field[j + i]:= Buffer; end; if (j + i < Right) then begin Inc(i, 1); end else begin i:= 1; Inc(j, 1); end; end;end;
function GetMaxStringSize(const Field1: array of string): integer;var i: integer;begin for i:= 0 to ArrayHigh(Field1) do begin if (length(Field1[i]) > Result) then begin Result:= length(Field1[i]); end; end;end;function FillWith(const Filler: char; Amount: integer): string;var i: integer;begin for i:= 1 to Amount do begin Result:= Filler + Result; end;end;procedure SelectionSort(const Bunch: array of string; Left, Right: integer);var Buffer: string; i, j, m: integer;begin i:= 1; m:= GetMaxStringSize(Bunch); while (j < Right) do begin Bunch[j]:= FillWith('0', m - length(Bunch[j])); Bunch[j + i]:= FillWith('0', m - length(Bunch[j + i])); if (Bunch[j] > Bunch[j + i]) then begin Buffer:= Bunch[j]; Bunch[j]:= Bunch[j + i]; Bunch[j + i]:= Buffer; end; if (j + i < Right) then begin Inc(i, 1); end else begin i:= 1; Inc(j, 1); end; end;end;function IXSplit(const SOURCE: string; Delimiter: string): array of string;var i, x, d: integer; s, b: string;begin d:= length(Delimiter); i:= 1; SetArrayLength(Result, 0); while (i <= length(SOURCE)) do begin s:= Copy(SOURCE, i, d); if (s = Delimiter) then begin SetArrayLength(Result, x + 1); Result[x]:= b; Inc(i, d); Inc(x, 1); b:= ''; end else begin b:= b + Copy(s, 1, 1); Inc(i, 1); end; end; if (b <> '') then begin SetArrayLength(Result, x + 1); Result[x]:= b; end;end;procedure ActivateServer();var i: integer; a: array of string;begin a:= IXSplit(ReadFile('compare.txt'), #13#10); SelectionSort(a, 0, GetArrayLength(a) - 1); for i:= 0 to ArrayHigh(a) do begin WriteLn(a[i]); end;end;
2004400300111-10-299000455524129872315621