在下面的例子:
matrix[column][row]
是 'myMatrix的' 型是如何構造的。只需遍歷第一個數組並將其發送到您的測試函數。
此外,在測試功能中,請確保您將結果設置爲false以開始!
type
myArray = array [1..10] of integer;
myMatrix = array[1..10] of myArray;
var
matrix: myMatrix;
function noRepeat(const A: myArray): Boolean;
var
i: integer;
begin
//Result := true; //?
Result := false;
for i:=1 to high(A) do
for j := i + 1 to high(A) do
if (A[i] = A[j]) then
Result := true;
end;
procedure sendColumn;
var
b, wasRepeat: boolean;
i: Integer;
Begin
for i := low(matrix) to high(matrix) do
Begin
b := noRepeat(matrix[i]);
if b then
wasRepeat := true;
End;
End;
如果行很大,那麼你必須通知測試例程你想測試哪一列。
type
myArray = array [1..10] of integer;
myMatrix = array[1..10] of myArray;
var
matrix: myMatrix;
function noRepeat(const A: myMatrix; Col: Integer): Boolean;
var
i, j: integer;
begin
Result := false;
for i := low(A) to high(A) do
for j := i + low(A) to high(A) do
if (A[i][Col] = A[j][Col]) then
Result := true;
end;
procedure sendColumn;
var
b, wasRepeat: boolean;
i: Integer;
Begin
for i := 1 to 10 do
Begin
b := noRepeat(matrix, i);
if b then
wasRepeat := true;
End;
End;
在m×n矩陣,其中M是行大小並且N是列大小,這會給你colums
:對於i:= 0到n做對於j:= 0 m的[I,J]。 – 2012-12-25 21:02:09
你的矩陣類型定義是怎樣的? – balazs
通過const傳遞數組。不要複製它們。使用開放數組。不需要明確地傳遞長度,如果你的數組非常重要,那麼你需要將列挑出到一個臨時數組中,並通過它。 –