class Trans
feature
	Create is
	local
		a,b: ARRAY2[INTEGER];
		x,y: INTEGER
	do
		a.create(5,2);
		io.putstring("Width: ");  io.putint(a.width); io.new_line;
		io.putstring("Height: "); io.putint(a.height); io.new_line;
		
		-- a initialisieren
		FROM x:= 1
		UNTIL x > a.width
		LOOP
			FROM y:= 1
			UNTIL y > a.height
			LOOP
				a.put(10*x + y, y, x);
				y:= y + 1
			END;
			x:= x + 1
		END;
		
		print(a);
		io.new_line;
		
		b:= transpose(a);
		
		print(b);
		io.new_line;
	end;
	
	print(a: ARRAY2[INTEGER]) IS
	REQUIRE NOT a.Void
	LOCAL x,y: INTEGER
	DO
		FROM x:= 1
		UNTIL x > a.width
		LOOP
			FROM y:= 1
			UNTIL y > a.height
			LOOP
				io.putint(a.item(y,x));
				io.putchar('\t');
				y:= y + 1
			END;
			io.new_line;
			x:= x + 1
		END;
	END;
	
	
	transpose(a: ARRAY2[INTEGER]): ARRAY2[INTEGER] IS
	REQUIRE NOT a.Void
	LOCAL x,y: INTEGER
	DO
		Result.Create(a.width, a.height);
		
		FROM
			x:= 1
		INVARIANT
			x <= a.width + 1;
			ForAll j:[1..x-1]. ForAll i: [1..a.height]. a.item(i,j) = Result.item(j,i)
		VARIANT
			a.width + 1 - x
		UNTIL
			x > a.width
		LOOP
			FROM
				y:= 1
			INVARIANT
				y <= a.height + 1;
				ForAll i: [1..y-1]. a.item(i,x) = Result.item(x,i)
			VARIANT
				a.height + 1 - y
			UNTIL
				y > a.height				
			LOOP
				Result.put(a.item(y,x),x,y);
				y:= y + 1
			END;
			x:= x + 1
		END
	ENSURE
		NOT Result.Void;
		Result.width = a.height AND Result.height = a.width;
		ForAll j:[1..a.width]. ForAll i: [1..a.height]. a.item(i,j) = Result.item(j,i)
	end
end
	
