/**
 * struct TreeNode {
 *	int val;
 *	struct TreeNode *left;
 *	struct TreeNode *right;
 * };
 *
 * C语言声明定义全局变量请加上static,防止重复定义
 */

/**
 * 
 * @param pRootOfTree TreeNode类 
 * @return TreeNode类
 */
static struct TreeNode *pre;
//这里需要加static才能正确定义
void Inorder(struct TreeNode *pRoot)
{
  if (!pRoot)
    return;

  Inorder(pRoot->left);
  pRoot->left = pre;
  if (pre)
    pre->right = pRoot;
  pre = pRoot;
  Inorder(pRoot->right);
}

//中序遍历

struct TreeNode *Convert(struct TreeNode *pRootOfTree)
{

  struct TreeNode *p;
  p = pRootOfTree;
  if (p)
  {
    while (p->left)
      p = p->left;
    pre = p->left;
    Inorder(pRootOfTree);
  }
  return p;
}