(*  Tietorakenteet ja algoritmit 1999 *)
(*    Esimerkki 3-8 : Puun tulostaminen sisäjärjestyksessä *)
(*   9.9.1999 MM *)
(*    main:issa luodaan seuraavanlainen puu: *)
(*       4      *)
(*     / | \    *)
(*    5  6  8   *)
(*       |      *)
(*       7      *)

program Esim3_8;
 
import TRA;

procedure preorder_print(T:TREE;n:TREE_NODE);
begin
	TREE_PRINT_NODE(T, n); 
	writeln(' ');
	n:=TREE_LEFTMOST_CHILD(T, n);
	while (n<>NIL) do
		begin
		 preorder_print(T, n);
		 n := TREE_RIGHT_SIBLING(T, n);
		end;
end;

var	T:TREE;
	n,apu:TREE_NODE;
begin
	INT_TREE_CREATE(T);
	apu:=INT_TREE_CREATE_NODE(4);
	TREE_ASSIGN_ROOT(T, apu);
	TREE_ASSIGN_LEFTMOST_CHILD(T, TREE_ROOT(T),INT_TREE_CREATE_NODE(5));
	n := TREE_LEFTMOST_CHILD(T, TREE_ROOT(T));
	TREE_ASSIGN_RIGHT_SIBLING(T, n, INT_TREE_CREATE_NODE(6));
	n := TREE_RIGHT_SIBLING(T, n);
	TREE_ASSIGN_LEFTMOST_CHILD(T, n, INT_TREE_CREATE_NODE(7));
	TREE_ASSIGN_RIGHT_SIBLING(T, n, INT_TREE_CREATE_NODE(8));
	preorder_print(T, TREE_ROOT(T));	
	writeln;
end.
