add another solution for converting binary search tree to doubly linked list without using global variable