- 4
- 0
- 约6.22千字
- 约 20页
- 2017-10-06 发布于河南
- 举报
平衡二叉树c语言代码(Balanced two fork tree c language code)
平衡二叉树c语言代码(Balanced two fork tree c language code)
[
*
Program Author: monkeylee
Program name: two tree balance factor
Program function: randomly generate the number of integers required by users, generate two fork tree (without duplication),
Can generate, traverse, find two fork tree, and dynamic search,
If the node is not found, the value is added to the tree
It can display the generation sequence, balance factor (failure) and node value of the node
* /
#includestdio.h
#includestdlib.h
#includetime.h
/ / self reference structure
Struct treeNode
{
Int data; / / node value
Int balance; / / balance factor
Int order; / / build order
Struct treeNode *left; / / pointer to the left sub tree
Struct treeNode *right; / / pointer to the right subtree.
Struct treeNode *father;
}; / * * / END structure definition
Typedef struct treeNode TreeNode;
Typedef TreeNode * TreeNodePtr;
The function prototype / * * /
Void insertNode (TreeNodePtr rootPtr, int value, int order); / / insert node
Void inOrder (TreeNodePtr rootPtr); / / in order traversal
Int (instructions); / / menu
Void search (TreeNodePtr rootPtr, int value, int n); / / search
//----------------------------------------------------------------------------------
The main function of / * * /
Void, main ()
{
Int item; / / the data to be operated
Int choices; / / storage mechanism with variable
Int i; / / loop counter
Int n; / / the number of nodes
TreeNodePtr rootPtr=NULL; / / tree is empty in the beginning
While (choices=instructions ())
{
Switch (choices)
{
Case 1:
RootPtr=NULL;
Printf (enter the number of nodes to generate two forks);
Scanf (%d, n);
If (n=0)
{
Printf (the number of input nodes must be greater than or equal to 1\n);
Break;
}
Srand (time (NULL));
For (i=1; i=n; i++)
{
Item=rand ()% (10*n);
InsertNode (rootPtr, item, I);
}/*END for*/
Break;
Case 2:
Printf (preorder traversal: \n);
If (rootPtr==NULL)
Break;
InOrder (rootPtr);
Printf (\n);
Break;
Case 3:
Printf (enter the number to be found);
Scanf (%d, item);
您可能关注的文档
- 室内设计风格对比(Interior design style contrast).doc
- 家常食物食疗特点和功效(Characteristics and efficacy of home food therapy).doc
- 家庭常备otc乙类(Family standing OTC B.).doc
- 家庭教育专家 让孩子受人欢迎的八大魔法(Family education experts give children the eight magic of popularity).doc
- 家居装修详细流程说明(Detailed description of the process of home decoration).doc
- 家庭治疗模式(Family therapy model).doc
- 家庭生活妙招(Family life coup).doc
- 家庭生活妙招71613(Family life coup 71613).doc
- 家庭电路(Home circuit).doc
- 家庭装潢中的电气设计和安装(Electrical design and installation in home decor).doc
最近下载
- 2026年浙江档案职称考试(档案工作实务)历年参考题库含答案详解.docx VIP
- 南通佳宜有限公司办公楼建筑结构设计.docx
- 拼拼豆教程及图案汇总[已排版可直接打印].doc VIP
- 共情传播视角下的网络微短剧叙事分析.docx VIP
- 贵阳市2024届高三适应性考试(一)一模物理试卷(含答案).docx
- 高中物理运动和力的关系10道计算题专题.docx VIP
- 语言学及应用语言学专业硕士研究生培养方案﹙050102﹚.docx VIP
- 10以内加减混合填空题(30页).docx
- 三相四线电能表不接零线电量分析0516..doc VIP
- 2025年乡村医生招聘考试试题题及答案.docx VIP
原创力文档

文档评论(0)