ch6 program added using tree structure and memory allocation