function output_tree(T,Tb,position)
% OUTPUT_TREE displays the necessary information for the output of the
%	decision tree generated 
%	
%	output_tree(T,Tb,position)
%
%	T: matrix representing decision tree T.
%	Tb: matrix representing the point-breakdown of sets A and B by T
%	position
global count;

[rowT,colT] = size(T);
[rowTb,colTb] = size(Tb);
n = rowT - 4;

if (count < 10 )
	b = 6;
elseif ( count < 100 )
	b = 5;
end

% display the parent node:

disp([ num2str(count) blanks(b) sprintf('%7.3f ',(T(1:n,position))) '    ' sprintf('%7.3f ',(T(n+1,position))) '  ' sprintf('%7d ',(Tb(1,position))) '   ' '  ' sprintf('%7d ',(Tb(2,position))) ])

disp(blanks(1)')

count = count + 1;

% check to see if left child is a leaf:

if (T(n+2,position) ~= -1 )
	new_position = T(n+2,position);
	output_tree(T,Tb,new_position);

else	% the left child is a leaf node:

	if (count < 10 )
		b = 7;
	elseif (count < 100 )
		b = 6;
	end

% display the info about the left child leaf node:
disp([ num2str(count) blanks(b) 'Leaf Node' blanks(8*n-8) '     ' blanks(7)  sprintf('%7d ',(Tb(3,position))) '     '  sprintf('%7d ',(Tb(4,position))) ])

disp(blanks(1)')

count = count + 1;

end

if (T(n+3,position) ~= -1 )
	new_position = T(n+3,position);
	output_tree(T,Tb,new_position);

else	% the right child is a leaf node


	if (count < 10 )
		b = 7;
	elseif (count < 100 )
		b = 6;
	end

disp([ num2str(count) blanks(b) 'Leaf Node' blanks(8*n-8) '     ' blanks(6) ' ' sprintf('%7d ',(Tb(5,position))) '   ' '  ' sprintf('%7d ',(Tb(6,position))) ])

disp(blanks(1)')

count = count + 1;
end


