示例#1
0
 bool findSmall(TreeNode *root, TreeNode **pre) {
     if (root == NULL)
         return false;
     bool find = findSmall(root->left, pre);
     if (find)
         return true;
     if (root->val < (*pre)->val) {
         return true;
     }
     *pre = root;
     return findSmall(root->right, pre);
 }
示例#2
0
 bool findSmall(TreeNode *root, int &pre) {
     if (root == NULL)
         return false;
     bool find = findSmall(root->left, pre);
     if (find)
         return true;
     if (root->val < pre) {
         return true;
     }
     small = root;
     pre = root->val;
     return findSmall(root->right, pre);
 }
示例#3
0
int main()
{
	int testArr[8] = { 1, 2, 4, 5, 10, 100, 2, -22 };

	// prints smallest number in array
	std::cout << findSmall(testArr, 8) << std::endl; 

}
示例#4
0
 void recoverTree(TreeNode *root) {
     // Start typing your C/C++ solution below
     // DO NOT write int main() function
     TreeNode *p = new TreeNode(INT_MIN);
     TreeNode *l = new TreeNode(INT_MAX);
     findSmall(root, &p);
     findBig(root, &l);
     
     int temp = p->val;
     p->val = l->val;
     l->val = temp;
 }
示例#5
0
 void recoverTree(TreeNode *root) {
     // Start typing your C/C++ solution below
     // DO NOT write int main() function
     int pre = INT_MIN;
     int lat = INT_MAX;
     findSmall(root, pre);
     findBig(root, lat);
     
     int temp = small->val;
     small->val = big->val;
     big->val = temp;
     
 }