class Solution {
public:
    TreeNode* Convert(TreeNode* pRootOfTree)
    {
        if (pRootOfTree == nullptr)
            return pRootOfTree;

        auto pin = pRootOfTree;
        Inorder(pin);

        ivec.front()->left = nullptr;
        ivec.back()->right = nullptr;
        int length = ivec.size();
        for (int i = 0; i != length-1; ++i){
            ivec[i]->right = ivec[i+1];
            ivec[i+1]->left = ivec[i];
        }
        return ivec.front();
    }
    
    void Inorder(TreeNode* T){
        if(T != nullptr){
            Inorder(T -> left);
            ivec.push_back(T);
            Inorder(T -> right);
        }
    }
private:
    vector<TreeNode*> ivec;
};