typedef struct node
{
/*ElemType*/int m_Data;
int m_LTag;
int m_RTag;
struct node* m_LChild;
struct node* m_RChild;
} ThreadTreeNode;
ThreadTreeNode* pre = NULL;
ThreadTreeNode* CreateThread(ThreadTreeNode* Tree)
{
ThreadTreeNode* root = (ThreadTreeNode*) malloc(sizeof(ThreadTreeNode));
root->m_LTag = 0;
root->m_RTag = 1;
root->m_RChild = Tree;
if (Tree == NULL)
{
root->LChild = root;
}
else
{
root->LChild = Tree;
pre = root;
Thread(Tree);
pre->m_RTag = 1;
pre->m_RChild = root;
root->m_RChild = pre;
}
return root;
}
void Thread(ThreadTreeNode* &tree)
{
Thread(tree->m_LChild);
if (tree->m_LChild != NULL)
{
tree->m_LTag = 0;
}
else
{
tree->m_LTag = 1;
tree->LChild = pre;
}
if (pre->m_RChild != NULL)
{
pre->m_RTag = 0;
}
else
{
pre->m_RTag = 1;
pre->m_RChild = p;
}
pre = p;
Thread(tree->m_RChild);
}
void InOrderThreadBT(ThreadTreeNode* Tree)
{
ThreadTreeNode* p = Tree->LChild;
while (p != Tree)
{
while (p->m_LChild != NULL)
{
p = p->m_LChild;
}
cout << p->m_Data << endl;
if (p->m_RTag == 1 && p->m_RChild != Tree)
{
p = p->m_RChild;
cout << p->Data;
}
p = p->m_RChild;
}
}