标签:while 双向链表 剑指offer void oid amp public nbsp tree
//肯定是要用中序遍历。。。可是开始不怎么会弄 //为什么这么菜 /* struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) { } };*/ class Solution { public: void ConvertSup(TreeNode* &proot,TreeNode* &pre) { ConvertSup(proot->left,pre); proot->left=pre; if(pre!=NULL) pre->right=proot; pre=proot; ConvertSup(proot->right,pre); } TreeNode* Convert(TreeNode* pRootOfTree) { TreeNode* pre=NULL; if(pRootOfTree==NULL) { return NULL; } ConvertSup(pRootOfTree,pre); TreeNode* cur=pRootOfTree; while(cur->left!=NULL) { cur=cur->left; } return cur; } };
标签:while 双向链表 剑指offer void oid amp public nbsp tree
原文地址:http://www.cnblogs.com/159269lzm/p/7291710.html