struct BinaryTreeNode{
int data;
BinaryTreeNode *left;
BinaryTreeNode *right;
};
void Convert_core(BinaryTreeNode *pNode,BinaryTreeNode **pLastNode){
//handle left subtree
if(pNode->left)
Convert_core(pNode->left,pLastNode);
//add pNode to the end of the lsit
pNode->left=*pLastNode;
if(*pLastNode)
*pLastNode->right=pNode;
*pLastNode=pNode;
//handle right subtree
if(pNode->right)
Convert_core(pNode->right,pLastNode);
}
BinaryTreeNode* Convert(BinaryTreeNode *pRoot){
if(pRoot==NULL) return NULL;
//get last node
BinaryTreeNode *pLastNode=NULL;
Convert_core(pRoot,&pLastNode);
//get first node
BinaryTreeNode *pFirstNode=pLastNode;
while(pFirstNode->left){
pFirstNode=pFirstNode->left;
}
return pFirstNode;
}