flatten btree to linked list reimpl