Sir R. M8gic1an
2008-02-20 08:55:04
hey, made a couple array functions that could be useful:
BubbleSort (from Pascal) // scar already has this
Switch (from Pascal) // scar has this as swap(Arrayindex[1], ArrayIndex[2])
DeleteRecord
RMCombineTSA
BubbleSort sorts your array, from the smallest to the biggest int
Switch will change the position of the values in an array
DeleteRecord will delete a value from an array, and shorten it.
RMCombineTSA will make two TStringArrays into one.
you can run he whole thing to test it.
~RM
BubbleSort (from Pascal) // scar already has this
Switch (from Pascal) // scar has this as swap(Arrayindex[1], ArrayIndex[2])
DeleteRecord
RMCombineTSA
BubbleSort sorts your array, from the smallest to the biggest int
Switch will change the position of the values in an array
DeleteRecord will delete a value from an array, and shorten it.
RMCombineTSA will make two TStringArrays into one.
you can run he whole thing to test it.
procedure Switch(s:TIntegerArray; a, b:integer); //by RM, but common in pascal
var temp:integer;
begin
temp := s[a];
s[a] := s[b];
s[b] := temp;
end;
//DelRecord(i, 3);
//i[3] disappears and is replaced by i[4];
Function DelRecord(s:TIntegerArray; a:integer):TIntegerArray; //by RM
var x, y:integer;
begin
y:=High(s)-1;
for x:= a to y do
Switch(s, x, x+1);
SetArrayLength(s, Length(s)-1);
Result:= s;
end;
Procedure BubbleSort(numbers : TIntegerArray); // common in pascal, not by me
Var i, j, temp, size : Integer;
Begin
size:= Length(numbers)-1
For i := size DownTo 1 do
For j := 1 to i do
If (numbers[j-1] > numbers[j]) then
Begin
temp := numbers[j-1];
numbers[j-1] := numbers[j];
numbers[j] := temp;
End;
end;
Function RMCombineTSA(i, s:TStringArray):TStringArray;
var x, b, h:integer;
begin
Result:= i;
SetLength(Result, Length(i)+Length(s));
h := Length(Result);
b := Length(i)
for x:=b to h-1 do
Result[x] := s[x-b];
end;
var
i, b:TIntegerArray;
TSA:TStringArray;
x:integer;
begin
ClearDebug;
i:=[0, 10, 4, 8, 2, 6]
BubbleSort(i);
writeln('Sorting');
writeln('');
for x:=0 to High(i) do
writeln('x: '+IntToStr(x)+' - '+IntToStr(i[x]));
switch(i, 0, 2);
writeln('');
writeln('switch 0 with 2');
writeln('');
for x:=0 to High(i) do
writeln('y: '+IntToStr(x)+' - '+IntToStr(i[x]));
i := DelRecord(i, 2);
writeln('');
writeln('Deleting record 2');
writeln('');
for x:=0 to High(i) do
writeln('z: '+IntToStr(x)+' - '+IntToStr(i[x]));
wait(50);
writeln('combining "hello" and "hi" with "ciao" and "bye" using CombineTSA');
TSA := RMCombineTSA(['hello', 'hi'], ['ciao', 'bye']);
wait(2);
for x:=0 to High(TSA) do
writeln('TSA['+IntToStr(x)+']: '+TSA[x]);
end.
~RM