在下面的例子:
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传递数组。不要复制它们。使用开放数组。不需要明确地传递长度,如果你的数组非常重要,那么你需要将列挑出到一个临时数组中,并通过它。 –