	function distance( pq : tree ) : integer;
	begin
	if pq=nil then	distance := 0
		else	distance := pq^.dist
	end;

	procedure fixdist( pq : tree );
	var	temp : tree;
	begin
	if distance(pq^.left) < distance(pq^.right) then begin
		temp := pq^.right;
		pq^.right := pq^.left;
		pq^.left := temp
		end;
	pq^.dist := distance(pq^.right) + 1
	end;
