标签:thread can 索引 return str scanf scan creat size
前序遍历创建,中序遍历添加索引。。
typedef struct BiNode { char data; char ltag, rtag; struct BiNode *lchild, *rchild; }BiNode; void createTree(BiNode **root); void printTree(BiNode *root, int lever); void addThread(BiNode *root, BiNode *pre); void desTree(BiNode *root, BiNode *pre); int main(int argc, char *argv[]) { BiNode *root = NULL; BiNode pre; BiNode *prePointer = ⪯ int lever = 1; createTree(&root); printTree(root, lever); pre.ltag = ‘t‘; pre.lchild = root; addThread(root, prePointer); pre.rtag = ‘t‘; pre.rchild = prePointer; prePointer->rtag = ‘t‘; prePointer->rchild = ⪯ return 0; } void createTree(BiNode **root) { char el; scanf("%c", &el); if(el == ‘ ‘) { *root = NULL; }else { *root = (BiNode *)malloc(sizeof(BiNode)); (*root)->data = el; (*root)->ltag = ‘l‘; (*root)->rtag = ‘l‘; createTree(&((*root)->lchild)); createTree(&((*root)->rchild)); } } void printTree(BiNode *root, int lever) { if(root) { printf("data: %c, lever: %d \n", root->data, lever); printTree(root->lchild, lever+1); printTree(root->rchild, lever+1); } } void addThread(BiNode *root, BiNode *pre) { if(root) { if(pre->rchild == NULL) { pre->rtag = ‘t‘; pre->rchild = root; } if(root->lchild) { addThread(root->lchild, pre); }else { root->ltag = ‘t‘; root->lchild = pre; pre = root->lchild; } pre = root; addThread(root->rchild, pre); } } void desTree(BiNode *root, BiNode *pre) { }
标签:thread can 索引 return str scanf scan creat size
原文地址:http://www.cnblogs.com/buerr/p/7413860.html