MODULE matrix_ptr EXPORTS Main; IMPORT IO,Text, Fmt; TYPE array = ARRAY OF ARRAY OF INTEGER; array_ptr = REF array; PROCEDURE output_size(text : TEXT; size : INTEGER) : TEXT = BEGIN IF size > (Text.Length(text)+1) THEN RETURN(output_size(Text.Cat(" ",text), size)); END; RETURN(text); END output_size; PROCEDURE print_matrix(matrix : array_ptr) = BEGIN FOR spalte := FIRST(matrix^) TO LAST(matrix^) DO FOR zeile := FIRST(matrix^[FIRST(matrix^)]) TO LAST(matrix^[FIRST(matrix^)]) DO IO.Put(output_size(Fmt.Int(matrix^[spalte,zeile]),4)); IF zeile = LAST(matrix^[FIRST(matrix^)]) THEN IO.Put("\n"); END; END; END; END print_matrix; PROCEDURE get_matrix(zeile,spalte : INTEGER) : array_ptr = VAR tmp : array_ptr; BEGIN tmp := NEW(array_ptr, zeile, spalte); (* feld mit zeilen X spalten eintraegen *) FOR spalte := FIRST(tmp^) TO LAST(tmp^) DO FOR zeile := FIRST(tmp^[FIRST(tmp^)]) TO LAST(tmp^[FIRST(tmp^)]) DO tmp^[spalte,zeile] := spalte+zeile; END; END; RETURN(tmp); END get_matrix; VAR matrix : array_ptr; BEGIN (* damit umzugehen ist jetzt ganz einfach und dynamisch !!! *) matrix := get_matrix(5,10); (* neue matrix holen *) print_matrix(matrix); (* matrix ausgeben *) IO.Put("\n"); (* neue Zeile *) (* eine andere matrix bitte! =) *) matrix := get_matrix(3, 3); (* neue matrix holen *) print_matrix(matrix); (* matrix ausgeben *) IO.Put("\n"); (* neue Zeile *) (* oder soetwas *grins* *) matrix := get_matrix(1, 11); (* neue matrix holen *) print_matrix(matrix); (* matrix ausgeben *) IO.Put("\n"); (* neue Zeile *) END matrix_ptr.