flatten binary tree