#include <iostream> using namespace std;
Enum Pointtag {LINK, THREAD,};
struct Bintreethingnode {char _data;
Bintreethingnode*_left;
Bintreethingnode*_right;
Pointtag _lefttag;
Pointtag _righttag; Bintreethingnode (const char &data): _data (data), _left (null), _right (null), _lefttag (LINK), _righttag (LI
NK) {}};
Class Bintreethreading {public:bintreethreading (const char *str) {_creatbintreethreading (_ROOT,STR);//recursively Create two fork tree}
void Postthread ()//subsequent clue {bintreethingnode*prev = NULL;
_postoderthread (_root, prev);
}//subsequent threaded traversal of void Postsort () {bintreethingnode*cur = _root;
Bintreethingnode *lastvisited = NULL; while (cur) {//always looking for the leftmost leaf node of the two-fork tree cur as the root node//cur->_left!= lastvisited: When cur is found through its left child, do not repeat cur to find the leftmost leaf node W
Hile (Cur&&cur->_lefttag!= thread&& cur->_left!= lastvisited) {cur = cur->_left;
if (cur && cur->_righttag = THREAD)///When Cur has no right child, cur can be accessed { cout << cur->_data << "";
lastvisited = cur;
} if (cur = = _root&&cur->_right = NULL)//When the root node is accessed, the traversal completes {cout << cur->_data << "";
Return
} cur = cur->_right; When Cur's right child is visited, cur can be accessed. And you know cur no successor, so start looking for the root node of cur while (cur && cur->_right = = lastvisited) {cout << Cur->_data <
< "";
lastvisited = cur; _parent (_root, &cur);
Find the root node of cur if (cur = = lastvisited) {return; }//while processing is: When Cur is found through its right child} protected:///recursively create two-fork tree void _creatbintreethreading (Bintreethingnode*&root,
const char *&STR {if (*str!= ' # ' &&*str!= ' ") {root = new Bintreethingnode (*STR);
_creatbintreethreading (Root->_left, ++STR);
if (*str!= ' ") {_creatbintreethreading (root->_right, ++STR); Find the root node of the current node void _parent (Bintreethingnode *&root,bintreethingnode **child) {Bintreethingnode *tmp = *ch Ild;
if (*child = = root) {return;
} if (root) {if (Root->_left = = *child | | root->_right = = *child) {*child = root;
Return
} if (Root->_lefttag = LINK) {_parent (root->_left, child);
} if (tmp = = *child&&root->_righttag = LINK) {_parent (root->_right, child); implementation void _postoderthread (Bintreethingnode*&cur, Bintreethingnode*&prev) {if (cur) {i
F (Cur->_lefttag = LINK) {_postoderthread (cur->_left, prev);
} if (Cur->_righttag = LINK) {_postoderthread (cur->_right, prev);
} if (Cur->_left = = NULL) {Cur->_lefttag = THREAD;
Cur->_left = prev;
} if (prev&&prev->_right = = NULL) {Prev->_righttag = THREAD;
Prev->_right = cur;
} prev = cur;
}} Private:bintreethingnode*_root;
};