




已阅读5页,还剩7页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
体系结构作业 学号:00847001 姓名:王川总 班级:软件二班using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;/* 界面* /namespace BinaryTree using BinaryTree1; public partial class Form1 : Form Node node; BinaryTrees bt; public Form1() InitializeComponent(); private void Form1_Load(object sender, EventArgs e) button1.Enabled = false; button3.Enabled = false; button2.Enabled = false; private void button5_Click(object sender, EventArgs e) if (textBox1.Text.Length != 0) listBox1.ClearSelected(); char , aa = new char50,50; for (int i = 0; i 50; i+) for (int j = 0; j 50; j+) aai, j = ; node = new Node(); bt = new BinaryTrees(textBox1.Text); node = bt.CreateBT(node); bt.initial(node); bt.Count(node); int x = bt.RootPoint(node); bt.DrawPoint(node,x,0,aa); bt.DrawLine(node, aa); for (int i = 0; i 50; i+) String s=; for (int j = 0; j r_h?l_h:r_h; else return 0; /* * 求出每个结点所在树中高度 */ public void initial(Node t) if (t != null) t.lchildHeigth = heigth(t.lchild); t.rchildHeigth = heigth(t.rchild); initial(t.lchild); initial(t.rchild); /* * 设置每个结点与左右子女结点的距离 ,根据根结点的左?右?标记确定到左,右孩子结点的距离 */ public void Count(Node t) if (t != null) if (t.flag = Left_Right.left) / 当父结点标记是左时 if (t.rchild != null & t.lchild != null) t.rchildDistance = 2; if (t.rchildHeigth = 2) t.lchildDistance = (t.rchildHeigth - 1) * 2+1; else t.lchildDistance = 2; else if (t.lchild = null & t.rchild = null) return; else if (t.lchild != null) t.lchildDistance = 2; t.rchildDistance = 0; else if (t.rchild != null) t.rchildDistance = 2; t.lchildDistance = 0; else if (t.flag = Left_Right.right) / 当父结点标记是右时 if (t.rchild != null & t.lchild != null) t.lchildDistance = 2; if (t.lchildHeigth = 2) t.rchildDistance = (t.lchildHeigth - 1) * 2+1; else t.rchildDistance = 2; else if (t.rchild = null & t.lchild = null) return; else if (t.rchild != null) t.rchildDistance = 2; t.lchildDistance = 0; else if (t.lchild != null) t.lchildDistance = 2; t.rchildDistance = 0; / else if / 递归遍历设置到每一个结点 Count(t.lchild); Count(t.rchild); / if /* * 计算出根结点的x坐标位置 */ public int RootPoint(Node t) int count =0; /* * 由于算法的实现是使得右边的结点总超不过左边的长度, 故只要求出所有的左边的长度即可 */ if (t != null) count = t.lchildDistance; count += RootPoint(t.lchild); return count; else return 0; /* * 画结点 */ public void DrawPoint(Node t, int x, int y,char , point) if (t != null) pointy,x = t.data; t.x = x; t.y= y; DrawPoint(t.lchild, x - t.lchildDistance, y + t.lchildDistance,point); DrawPoint(t.rchild, x + t.rchildDistance, y + t.rchildDistance,point); /* * 画线,树中的线 */ public void DrawLine(Node t, char, point) if (t != null) int x1, y1, x2, y2; x1 = t.x; y1 = t.y; if (t.lchild != null) x2 = t.lchild.x; y2 = t.lchild.y; for (int x = x1-1, y = y1+1; x x2; x-, y+) pointy, x = /; if (t.rchild != nu
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年中国希伯胺原料药行业市场分析及投资价值评估前景预测报告
- 核电电焊工考试题及答案
- 2025年中国无线垂直鼠标行业市场分析及投资价值评估前景预测报告
- 用户行为分析-第149篇-洞察与解读
- 肿瘤免疫治疗专利布局-洞察与解读
- 2025国考常州市生态保护岗位申论必刷题及答案
- 2025国考福建金融监管局行测数量关系预测卷及答案
- 2025国考廊坊市法律事务岗位申论题库含答案
- 2025国考人社部行测数量关系易错点
- 2025国考丹东市纪检监察岗位行测题库含答案
- 2025-2030中国骆驼奶制品营养价值研究及产业化开发可行性分析报告
- 2025年南通市中考语文试题卷(含答案)
- 宁乡辅警考试试卷必刷题
- 高端定制家具成本优化2025年研究报告
- 2025年-《中华民族共同体概论》课后习题答案-新版
- 2025重庆碳管家科技有限公司招聘1人笔试历年参考题库附带答案详解
- 吊装储罐施工方案
- 尾矿库施工安全培训课件
- 智慧政务智能人事管理系统创新创业项目商业计划书
- 2025年电工证考试题及答案测试卷测试题(答案)
- 2025年全国统一驾驶证科目一考试题库(附答案)
评论
0/150
提交评论