创建一个结构体
C语言风格 写起来比较舒服
void CreateBitree(BsTreeNode * &pRoot,int * &arr);
void change(BsTreeNode * node,BsTreeNode * &pTail);
struct BsTreenode
{
int m_value;
BsTreenode *m_left;
BsTreenode *m_right;
};
void main()
{
BsTreeNode *pRoot=NULL;
BsTreeNode*pTail = NULL;
int arr[] = { 10 ,6 ,4 ,0, 0, 8, 0, 0, 14, 12, 0, 0, 16, 0, 0 };
int *ptr = arr;
CreateBitree(pRoot, ptr);
change(pRoot,pTail);
while (NULL != pTail)
{
cout << pTail->m_nvalue<<" ";
pTail = pTail->m_pLeft;
}
cout << endl;
system("pause");
}
void CreateBitree(BsTreeNode * &pRoot,int * &arr)
{
int dat;
dat = *arr;
++arr;
if (dat == 0)
{
pRoot = NULL;
}
else
{
pRoot = new BsTreeNode;
pRoot->m_nvalue = dat;
CreateBitree(pRoot->m_pLeft, arr);
CreateBitree(pRoot->m_Right, arr);
}
}
void change(BsTreeNode * node,BsTreeNode * &pTail)
{
if (node)
{
change(node->m_pLeft, pTail);
if (pTail)
{
pTail->m_Right = node;
}
node->m_pLeft = pTail;
pTail = node;
change(node->m_Right, pTail);
}
}