二叉树画法

上传人:F****n 文档编号:98256183 上传时间:2019-09-09 格式:DOC 页数:12 大小:137.50KB
返回 下载 相关 举报
二叉树画法_第1页
第1页 / 共12页
二叉树画法_第2页
第2页 / 共12页
二叉树画法_第3页
第3页 / 共12页
二叉树画法_第4页
第4页 / 共12页
二叉树画法_第5页
第5页 / 共12页
点击查看更多>>
资源描述

《二叉树画法》由会员分享,可在线阅读,更多相关《二叉树画法(12页珍藏版)》请在金锄头文库上搜索。

1、体系结构作业 学号: 姓名:王川总 班级:软件二班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; Binary

2、Trees 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 = n

3、ew 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+) Str

4、ing s=; for (int j = 0; j 50; j+) s += aai, j.ToString(); listBox1.Items.Add(s); button1.Enabled = true; button3.Enabled = true; button2.Enabled = true; textBox1.Text = ; else MessageBox.Show(请输入前序扩充序列!); private void button1_Click(object sender, EventArgs e) string ss = bt.PreOrder(node); label3.Te

5、xt = 前序遍历结果:; textBox2.Text = ss; private void button2_Click(object sender, EventArgs e) string ss = bt.MidOrder(node); label3.Text = 中序遍历结果:; textBox2.Text = ss; private void button3_Click(object sender, EventArgs e) string ss = bt.PostOrder(node); label3.Text = 后续遍历结果:; textBox2.Text = ss; private

6、 void label3_Click(object sender, EventArgs e) /* * 二叉树 * /namespace BinaryTree1 public enum Left_Right left, right ; public class Node public char data; /存放结点数据 public Node lchild; / 左子树 public Node rchild; /右子树 public Left_Right flag; / 标志该结点为左 或右,这里不一定和左右子树相对应 public int lchildHeigth; / 左子树的高度 pu

7、blic int rchildHeigth; / 右子树的高度 public int lchildDistance; / 根结点到左子树的距离 public int rchildDistance; / 根节点到右子树的距离 public int x; / 结点位置的x坐标 public int y; / 节点位置的y坐标 public Node() flag = Left_Right.left; lchildHeigth = 0; rchildHeigth = 0; lchild = null; rchild = null; lchildDistance = 0; rchildDistance

8、 = 0; public class BinaryTrees Node root; int count; char c; public BinaryTrees(string ss) count = 0; c = ss.ToCharArray(); public Node CreateBT(Node t) if (ccount != ) / 每个结点的数值先是放于数组中,创建时需要一个个从数组中读取 t.data = ccount+; t.lchild = new Node(); t.rchild = new Node();/ 设置结点标志 为以后画树使用到 if (t.flag = Left_Right.left) t.lchild.flag = Left_Right.left; t.rchild.flag = Left_Right.right; else t.lchild.flag = Left_Right.right; t.rchild.flag = Left_Right.left; t.lchild = CreateBT(t.lchild); t.rchild = CreateBT(t.rchild); else t =

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 教学/培训

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号