标签:style blog color sp div c log amp r
RT
传入3个参数 <根节点,上次访问的节点,头结点>。Yahoo二面被问到!完跪....
1 void BST2DoubleList(TreeNode *root, TreeNode *& prev, TreeNode *& head) { 2 if (root == NULL) 3 return; 4 BST2DoubleList(root->left, prev, head); 5 root->left = prev; 6 if (prev != NULL) 7 prev->right = root; 8 else 9 head = root; 10 prev = root; 11 BST2DoubleList(root->right, prev, head); 12 } 13 14 TreeNode* treeToDoublyList(TreeNode *root) { 15 TreeNode *prev = NULL; 16 TreeNode *head = NULL; 17 BST2DoubleList(root, prev, head); 18 return head; 19 }
标签:style blog color sp div c log amp r
原文地址:http://www.cnblogs.com/taizy/p/4002741.html