#define QUEUE_MAXSIZE 50
typedef char DATA; typedef enum { SubTree, Thread}NodeFlag;
//线索二叉树结构 typedef struct ThreadTree { DATA data; NodeFlag lflag; NodeFlag rflag; struct ThreadTree *left; struct ThreadTree *right; }ThreadBinTree;
ThreadBinTree *Previous = NULL;
//查找后继结点 ThreadBinTree *BinTreeNext_LDR(ThreadBinTree *bt) { ThreadBinTree *nextnode; if(!bt) return NULL; if(bt->rflag == Thread) return bt->right; else { nextnode=bt->right; while(nextnode->lflag == SubTree) nextnode=nextnode->left; return nextnode; }
}
//查找前驱结点
ThreadBinTree *BinTreePrevious_LDR(ThreadBinTree *bt) { ThreadBinTree *prenode; if(!bt) return NULL; if(bt->lflag == Thread) return bt->left; else { prenode = bt->left; while(prenode->rflag == SubTree) prenode = prenode->left; return prenode; }}
//遍历线索二叉树 void ThreadBinTree_LDR(ThreadBinTree *bt,void(*oper)(ThreadBinTree *p)) { if(bt) { while(bt->lflag == SubTree) bt=bt->left; do { oper(bt); bt=BinTreeNext_LDR(bt); }while(bt); } }