For the below test case, it will cause RE ! But it output 1 and 2.....So what happened when it return ???

```
[1,2]
1
```

Here is my implementation

```
class Solution {
public:
int kthSmallest(TreeNode* root, int k) {
TreeNode *pre, *cur;
int count=k, result=0;
cur=root;
while(cur){
if(cur->left){
pre=cur->left;
while(pre->right && pre->right!=cur) pre=pre->right;
if(!pre->right) {
pre->right=cur;
cur=cur->left;
}
else {
pre->right=NULL;
count--;
if(count==0) {
result=cur->val;
return result;
}
cur=cur->right;
}
}
else{
count--;
cout<<"1"<<endl;
if(count==0) {
result=cur->val;
cout<<"2"<<endl;
return result;
}
cur=cur->right;
}
}
return -1;
}
};
```