| 查看: 1305 | 回复: 8 | |||
[交流]
二叉树的动态创建已有4人参与
|
|
#include <stdio.h> #include <stdlib.h> #include <malloc.h> typedef struct node { char data; struct node *lchild, *rchild; }bnode,*btree; void createbtree(btree &t,int &n) { char x; btree q; n=n+1; printf("\nInput %d DATA:",n); x=getchar(); if(x!='\n')getchar(); if (x=='\n')return ; q=(btree)malloc(sizeof(bnode)); q->data=x; q->lchild=NULL; q->rchild=NULL; t=q; printf(" This Address is: %o, Data is: %c,\n Left Pointer is: %o, Right Pointer is: %o",q,q->data,q->lchild,q->rchild); createbtree(q->lchild,n); createbtree(q->rchild,n); return ; } void visit(btree e) { printf(" Address: %o, Data: %c, Left Pointer: %o, Right Pointer: %o\n",e,e->data,e->lchild,e->rchild); } void pretraverse(btree t) { if(t) { visit(t); pretraverse(t->lchild); pretraverse(t->rchild); } else return ; } void countleaf(btree t,int &c) { if(t!=NULL) { if (t->lchild==NULL && t->rchild==NULL) {c=c+1; } countleaf(t->lchild,c); countleaf(t->rchild,c); } } int treehigh(btree t) { int lh,rh,h; if(t==NULL) h=0; else { lh=treehigh(t->lchild); rh=treehigh(t->rchild); h=(lh>rh? lh:rh)+1; } return h; } int main() { btree t; int count=0,n=0; printf("\n Please input TREE Data:\n" ;createbtree(t,n); printf("\n This is TREE Struct: \n" ;pretraverse(t); countleaf(t,count); printf("\n This TREE has %d leaves, High of The TREE is: %d\n",count,treehigh(t)); return 0; } Sample Text有没有谁能看出输入语句是如何结束的? 动态创建二叉树的思路是什么? [ Last edited by 邦桀南瑜 on 2013-11-15 at 20:08 ] |
» 猜你喜欢
到新单位后,换了新的研究方向,没有团队,持续积累2区以上论文,能申请到面上吗
已经有6人回复
2025冷门绝学什么时候出结果
已经有7人回复
请问有评职称,把科研教学业绩算分排序的高校吗
已经有6人回复
Bioresource Technology期刊,第一次返修的时候被退回好几次了
已经有7人回复
真诚求助:手里的省社科项目结项要求主持人一篇中文核心,有什么渠道能发核心吗
已经有8人回复
寻求一种能扛住强氧化性腐蚀性的容器密封件
已经有5人回复
请问哪里可以有青B申请的本子可以借鉴一下。
已经有4人回复
请问下大家为什么这个铃木偶联几乎不反应呢
已经有5人回复
天津工业大学郑柳春团队欢迎化学化工、高分子化学或有机合成方向的博士生和硕士生加入
已经有4人回复
康复大学泰山学者周祺惠团队招收博士研究生
已经有6人回复

想念异地的你
金虫 (小有名气)
- 应助: 0 (幼儿园)
- 金币: 526.5
- 散金: 6
- 帖子: 117
- 在线: 69小时
- 虫号: 2659616
- 注册: 2013-09-16
- 性别: GG
- 专业: 控制理论与方法

2楼2013-11-15 23:44:04
yongcailiu
金虫 (小有名气)
- 应助: 63 (初中生)
- 金币: 2283.9
- 红花: 10
- 帖子: 181
- 在线: 250.4小时
- 虫号: 1406563
- 注册: 2011-09-18
- 性别: GG
- 专业: 计算数学与科学工程计算
3楼2013-11-16 07:53:14
programfanny
铁杆木虫 (正式写手)
- 应助: 11 (小学生)
- 金币: 7802.8
- 红花: 12
- 帖子: 917
- 在线: 745.5小时
- 虫号: 2633722
- 注册: 2013-09-04
- 专业: 计算机科学的基础理论
4楼2013-11-16 16:40:56

5楼2013-11-17 18:40:37

6楼2013-11-17 18:41:35
chentianyu1
木虫 (小有名气)
- 应助: 67 (初中生)
- 金币: 2579
- 散金: 66
- 帖子: 252
- 在线: 450.2小时
- 虫号: 532712
- 注册: 2008-03-25
- 性别: GG
- 专业: 计算机网络
7楼2013-11-18 20:16:53

8楼2013-11-20 22:28:55
chentianyu1
木虫 (小有名气)
- 应助: 67 (初中生)
- 金币: 2579
- 散金: 66
- 帖子: 252
- 在线: 450.2小时
- 虫号: 532712
- 注册: 2008-03-25
- 性别: GG
- 专业: 计算机网络
9楼2013-11-21 00:21:55













;
回复此楼