Sort tree structure