




已阅读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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2024-2025学年河南省郑州市八十八中八年级(下)期中数学试卷(含答案)
- 养殖小区出租合同范本
- 房东日常收租合同范本
- 公共平台转让合同范本
- 夫妻买房的合同范本
- 空房公寓出租合同范本
- 自家车队维修合同范本
- 车位分期还款合同范本
- 定制制服服装合同范本
- 农业种植西红柿合同范本
- 2025年高考(陕西、山西、青海、宁夏卷)历史真题及答案
- 关于奶茶店转让合同范本
- 2025年保税区面试题目及答案
- 公安基础知识培训课件
- 2025年期货高管考试题库及答案
- 2024年黑龙江省肇源县卫生系统招聘考试(护理学专业知识)题含答案
- 2025年江苏省南京市中考英语试卷
- 2025年政法委网格员考试题库
- 2025年新版期权知识考试题库带答案
- 无锡市公安局梁溪分局招聘警务辅助人员57人笔试模拟试题参考答案详解
- 2025年度养老护理员考试技师培训考试题(含答案)
评论
0/150
提交评论