⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 开始学C#的一点知识希望可以借鉴!文件在修改中!
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace Bitree
{
	/// <summary>
	/// Form1 的摘要说明。
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.ListBox listBox1;
		private System.Windows.Forms.Button btnCreate;
		private System.Windows.Forms.Button btnMidle;
		private biTree tr;
		private System.Windows.Forms.Button btnAdd;
		private System.Windows.Forms.Button btnFirst;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.TextBox txtAddItem;
		private System.Windows.Forms.TextBox txtDeleteRoot;
		private System.Windows.Forms.Button btnDelete;
		private System.Windows.Forms.Button btnLeafageCount;
		private System.Windows.Forms.Button btnClearListBox;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Form1()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
		}

		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows 窗体设计器生成的代码
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.btnCreate = new System.Windows.Forms.Button();
			this.btnAdd = new System.Windows.Forms.Button();
			this.btnMidle = new System.Windows.Forms.Button();
			this.btnDelete = new System.Windows.Forms.Button();
			this.listBox1 = new System.Windows.Forms.ListBox();
			this.btnFirst = new System.Windows.Forms.Button();
			this.btnLeafageCount = new System.Windows.Forms.Button();
			this.label1 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.txtAddItem = new System.Windows.Forms.TextBox();
			this.txtDeleteRoot = new System.Windows.Forms.TextBox();
			this.btnClearListBox = new System.Windows.Forms.Button();
			this.SuspendLayout();
			// 
			// btnCreate
			// 
			this.btnCreate.Location = new System.Drawing.Point(24, 272);
			this.btnCreate.Name = "btnCreate";
			this.btnCreate.Size = new System.Drawing.Size(96, 24);
			this.btnCreate.TabIndex = 0;
			this.btnCreate.Text = "创建";
			this.btnCreate.Click += new System.EventHandler(this.btnCreate_Click);
			// 
			// btnAdd
			// 
			this.btnAdd.Enabled = false;
			this.btnAdd.Location = new System.Drawing.Point(168, 320);
			this.btnAdd.Name = "btnAdd";
			this.btnAdd.Size = new System.Drawing.Size(64, 24);
			this.btnAdd.TabIndex = 1;
			this.btnAdd.Text = "添加";
			this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);
			// 
			// btnMidle
			// 
			this.btnMidle.Enabled = false;
			this.btnMidle.Location = new System.Drawing.Point(136, 272);
			this.btnMidle.Name = "btnMidle";
			this.btnMidle.Size = new System.Drawing.Size(96, 24);
			this.btnMidle.TabIndex = 2;
			this.btnMidle.Text = "中序遍历";
			this.btnMidle.Click += new System.EventHandler(this.btnMidle_Click);
			// 
			// btnDelete
			// 
			this.btnDelete.Enabled = false;
			this.btnDelete.Location = new System.Drawing.Point(392, 320);
			this.btnDelete.Name = "btnDelete";
			this.btnDelete.Size = new System.Drawing.Size(64, 24);
			this.btnDelete.TabIndex = 3;
			this.btnDelete.Text = "删除";
			this.btnDelete.Click += new System.EventHandler(this.btnDelete_Click);
			// 
			// listBox1
			// 
			this.listBox1.ItemHeight = 12;
			this.listBox1.Location = new System.Drawing.Point(0, 0);
			this.listBox1.Name = "listBox1";
			this.listBox1.SelectionMode = System.Windows.Forms.SelectionMode.MultiSimple;
			this.listBox1.Size = new System.Drawing.Size(520, 244);
			this.listBox1.TabIndex = 4;
			// 
			// btnFirst
			// 
			this.btnFirst.Enabled = false;
			this.btnFirst.Location = new System.Drawing.Point(248, 272);
			this.btnFirst.Name = "btnFirst";
			this.btnFirst.Size = new System.Drawing.Size(96, 24);
			this.btnFirst.TabIndex = 5;
			this.btnFirst.Text = "先序遍历";
			this.btnFirst.Click += new System.EventHandler(this.btnFirst_Click_1);
			// 
			// btnLeafageCount
			// 
			this.btnLeafageCount.Enabled = false;
			this.btnLeafageCount.Location = new System.Drawing.Point(360, 272);
			this.btnLeafageCount.Name = "btnLeafageCount";
			this.btnLeafageCount.Size = new System.Drawing.Size(96, 24);
			this.btnLeafageCount.TabIndex = 6;
			this.btnLeafageCount.Text = "叶子节点数";
			this.btnLeafageCount.Click += new System.EventHandler(this.btnLeafageCount_Click);
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(24, 328);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(72, 16);
			this.label1.TabIndex = 7;
			this.label1.Text = "添加元素:";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(248, 328);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(72, 16);
			this.label2.TabIndex = 8;
			this.label2.Text = "删除节点:";
			// 
			// txtAddItem
			// 
			this.txtAddItem.Location = new System.Drawing.Point(96, 320);
			this.txtAddItem.Name = "txtAddItem";
			this.txtAddItem.Size = new System.Drawing.Size(64, 21);
			this.txtAddItem.TabIndex = 9;
			this.txtAddItem.Text = "";
			// 
			// txtDeleteRoot
			// 
			this.txtDeleteRoot.Location = new System.Drawing.Point(320, 320);
			this.txtDeleteRoot.Name = "txtDeleteRoot";
			this.txtDeleteRoot.Size = new System.Drawing.Size(64, 21);
			this.txtDeleteRoot.TabIndex = 10;
			this.txtDeleteRoot.Text = "";
			// 
			// btnClearListBox
			// 
			this.btnClearListBox.Location = new System.Drawing.Point(464, 272);
			this.btnClearListBox.Name = "btnClearListBox";
			this.btnClearListBox.Size = new System.Drawing.Size(48, 80);
			this.btnClearListBox.TabIndex = 11;
			this.btnClearListBox.Text = "清空列表框";
			this.btnClearListBox.Click += new System.EventHandler(this.btnClearListBox_Click);
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(520, 366);
			this.Controls.Add(this.btnClearListBox);
			this.Controls.Add(this.txtDeleteRoot);
			this.Controls.Add(this.txtAddItem);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.btnLeafageCount);
			this.Controls.Add(this.btnFirst);
			this.Controls.Add(this.listBox1);
			this.Controls.Add(this.btnDelete);
			this.Controls.Add(this.btnMidle);
			this.Controls.Add(this.btnAdd);
			this.Controls.Add(this.btnCreate);
			this.Name = "Form1";
			this.Text = "Form1";
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// 应用程序的主入口点。
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}

		private void btnCreate_Click(object sender, System.EventArgs e)
		{
			int [] data = new int[10];
			Random rnd = new Random();
			for( int i = 0; i < data.Length; i++ )
			{
				data[i] = rnd.Next( 100 );
			}
//			int [] data = new int[]{20,15,35,12,30,56,1,25,36,20};
			this.tr = null;
			for( int i = 0; i < data.Length; i++ )
			{
				biTree.BTInsert( ref this.tr, data[i] );
			}

			this.btnFirst.Enabled = true;
			this.btnMidle.Enabled = true;
			this.btnDelete.Enabled = true;
			this.btnAdd.Enabled = true;
			this.btnLeafageCount.Enabled = true;
			this.btnCreate.Text = "重新创建";
		}

		private void btnMidle_Click(object sender, System.EventArgs e)
		{
			this.listBox1.Items.Add( biTree.LNR( this.tr ).ToString() );
		}

		private void btnAdd_Click(object sender, System.EventArgs e)
		{
			biTree.BTInsert( ref this.tr, System.Int32.Parse( this.txtAddItem.Text ) );
		}

		private void btnFirst_Click_1(object sender, System.EventArgs e)
		{
			this.listBox1.Items.Add( biTree.NLR( this.tr ).ToString() );
		}

		private void btnDelete_Click(object sender, System.EventArgs e)
		{
			biTree.BTDelete( ref this.tr, Convert.ToInt32( this.txtDeleteRoot.Text ) );
		}

		private void btnLeafageCount_Click(object sender, System.EventArgs e)
		{
			this.listBox1.Items.Add( "树叶个数为:" + biTree.LeafageCount( this.tr ).ToString() );
//			this.listBox1.Items.Add( biTree.LeafageCount( this.tr ).ToString() );
		}

		private void btnClearListBox_Click(object sender, System.EventArgs e)
		{
			this.listBox1.Items.Clear();
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -