开云体育app官方版下载v1.237 - ios/安卓/手机APP下载

日期:2017-12-15 12:12:20 人气:3

开云体育app官方版下载v1.237 - ios/安卓/手机APP下载

开云体育游戏介绍,开云体育app下载免费安装,开云体育官方网站下载,开云体育官网手机版入口最新网址#include #include #define MAXSIZE 100 //二叉树中最多的结点数  typedef char TElemType; typedef struct BiTNode { TElemType data; struct BiTNode *lchild,*rchild; }BiTNode,*BiTree; //定义函数指针 typedef void(* Visit)(BiTree); //二叉树的初始化
    A+
热门评论

求C语言版数据结构二叉树的先序遍历递归算法,不要伪码,要求能实现能运行的。谢过各位大佬了!

K&R中的一个实现,可以读取数字,插入二叉树,并且统计出现次数。最后输出,这里假设只读取正数,自己可以改getword函数 #include#include#include#include #define MAXLINE 100 struct num { int number; int count; struct num *left; struct num *right;} ; struct num *addtree(struct num *, char w[]);void treeprint(struct num *);int getword(char w[], int lim); int main(void){ struct num *root; char word[MAXLINE]; root = NULL; while (getword(word, MAXLINE) != EOF) if (isdigit(word[0])) root = addtree(root, word); treeprint(root); return 0;} int getword(char *word, int lim){ int c; int getch(); void ungetch(); char *w = word; while (isspace(c = getch())) ; if (c != EOF) *w++ = c; if (!isdigit(c)) { *w = '\0'; return c; } for (; --lim > 0; w++) { if (!isdigit(c = *w = getch())) { ungetch(c); break; } } *w = '\0'; return word[0];} struct num *talloc(void);struct num *addtree(struct num *p, char *w){ int cond; cond = atoi(w); // printf("---%d---\n", cond); if (p == NULL) { p = talloc(); p->number = cond; p->count = 1; p->left = p->right = NULL; } else if (cond == p->number) p->count++; else if (cond number) p->left = addtree(p->left, w); else p->right = addtree(p->right, w); return p;} void treeprint(struct num *p){ if (p != NULL) { treeprint(p->left); printf("%d\thas:%d\n", p->number, p->count); treeprint(p->right); }} struct num *talloc(void){ return (struct num *) malloc(sizeof(struct num));} #define BUFSIZE 100int bufp = 0;char bufline[BUFSIZE];int getch(void){ return (bufp > 0) ? bufline[--bufp] : getchar();}void ungetch(int c){ if (bufp < BUFSIZE) bufline[bufp++] = c; else printf("error : full\n");}

阅读全文

数据结构试验(用C语言)建立一棵二叉树,并用递归或者非递归的算法分别用先序。中序和后序遍历、谢谢

#define LEN sizeof(struct tree) #define NULL 0 #include #include struct tree { char data; struct tree *lchild,*rchild; }; //创建二叉树 struct tree *creat() { char c; struct tree *t; c=getchar(); if(c==' ') t=NULL; else { t=(struct tree*)malloc(LEN); t->data=c; t->lchild=creat(); t->rchild=creat(); } return t; } //前序遍历 void Preprint(struct tree*t) { if(t!=NULL) { printf("%c->",t->data); Preprint(t->lchild); Preprint(t->rchild); } } //中序遍历 void Inprint(struct tree*t) { if(t!=NULL) { Inprint(t->lchild); printf("%c->",t->data); Inprint(t->rchild); } } //后序遍历 void Postprint(struct tree*t) { if(t!=NULL) { Postprint(t->lchild); Postprint(t->rchild); printf("%c->",t->data); } } main() { struct tree *t; printf("Please input tree in order:\n"); t=creat(); printf("The result of Preorder traversal is\n"); Preprint(t); printf("^\nThe result of Inorder traversal is\n"); Inprint(t); printf("^\nThe result of Postorder traversal is\n"); Postprint(t); printf("^\n"); getch(); }

阅读全文