/*  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      
*/

#include "TRA.h"
#include <stdio.h>

void preorder_print(TREE T, TREE_NODE n) {
	TREE_PRINT_NODE(T, n); 
	putchar(' ');
	n = TREE_LEFTMOST_CHILD(T, n);
	while (n != TREE_NIL) {
		preorder_print(T, n);
		n = TREE_RIGHT_SIBLING(T, n);
	}
}

void main() {
	TREE T;
	TREE_NODE n;
	INT_TREE_CREATE(T);
	TREE_ASSIGN_ROOT(T, IT_CREATE_NODE(4));
	TREE_ASSIGN_LEFTMOST_CHILD(T, TREE_ROOT(T), IT_CREATE_NODE(5));
	n = TREE_LEFTMOST_CHILD(T, TREE_ROOT(T));
	TREE_ASSIGN_RIGHT_SIBLING(T, n, IT_CREATE_NODE(6));
	n = TREE_RIGHT_SIBLING(T, n);
	TREE_ASSIGN_LEFTMOST_CHILD(T, n, IT_CREATE_NODE(7));
	TREE_ASSIGN_RIGHT_SIBLING(T, n, IT_CREATE_NODE(8));
	preorder_print(T, TREE_ROOT(T));	
	putchar('\n');
}
