📄 testform.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace DataTypeDemo
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.RichTextBox richTextBox1;
/// <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.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.SuspendLayout();
//
// richTextBox1
//
this.richTextBox1.Dock = System.Windows.Forms.DockStyle.Fill;
this.richTextBox1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
this.richTextBox1.Location = new System.Drawing.Point(0, 0);
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.ReadOnly = true;
this.richTextBox1.Size = new System.Drawing.Size(426, 613);
this.richTextBox1.TabIndex = 0;
this.richTextBox1.Text = "";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(426, 613);
this.Controls.Add(this.richTextBox1);
this.MaximizeBox = false;
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "数据结构库演示";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
//title
this.richTextBox1.Text = " ***************数据结构演示*************** 作者:李俊";
this.richTextBox1.Text += "\n 源代码有全部注释,仅供参考!!! ";
this.richTextBox1.Text += "\n________________________________________________________________";
//The test data
string[] s = new string[]{"a","b", "c", "d","e","f","g","h","i","j","k"};
string ds = null;
for(int i=0; i<s.Length; i++)
{
ds += s[i] + ",";
}
this.richTextBox1.Text += "\n原始数据: "+ ds;
/*
* test some Type
*/
linkList link = new linkList();
link.CreateLinkList(s);
link.AddNode("l");
link.InsertNode("b1",2);
this.richTextBox1.Text += "\n\n测试双向链表: ";
for(int i =1;i<=link.Length;i++)
{
this.richTextBox1.Text += link.GetFindData(i).ToString()+",";
}
this.richTextBox1.Text += " (插入了b1)";
link.DeleteNode(3);
this.richTextBox1.Text += "\n ";
for(int i =1;i<=link.Length;i++)
{
this.richTextBox1.Text += link.GetFindData(i).ToString()+",";
}
this.richTextBox1.Text += " (插入了b1)";
/*
* test struct type opration
*/
Struct strobj = new Struct();
strobj.CreateStruct(s);
strobj.Push("l");
strobj.Push("m");
int len = strobj.Length;
this.richTextBox1.Text += "\n\n测试堆栈: ";
for(int i=0;i<len;i++)
{
this.richTextBox1.Text += strobj.Pop()+",";
}
this.richTextBox1.Text += " (push(\"l\")和(\"m\")并循环pop)";
/*
* test queue type opration
*/
Queue qobj = new Queue();
qobj.CreateQueue(s);
qobj.JoinQueue("l");
qobj.JoinQueue("m");
int lent = qobj.Length;
this.richTextBox1.Text += "\n\n测试队列: ";
for(int j=0;j<lent;j++)
{
this.richTextBox1.Text += qobj.OutQueue()+",";
}
this.richTextBox1.Text += " (入队l和m并循环出队)";
/*
* test tree type opration
*/
tree t = new tree();
t.CreateTree(s);
treeNode n = t.Root;
this.richTextBox1.Text += "\n\n测试三插链式树:(用的是自己设计的算法带入数组创建树,非递归实现)\n前序遍历: ";
this.fprintTree(n);
this.richTextBox1.Text += "\n中序遍历: ";
this.mprintTree(n);
this.richTextBox1.Text += "\n后序遍历: ";
this.bprintTree(n);
t.InsertRight("b","b1");
t.InsertLeft("c","c1");
this.richTextBox1.Text += "\n已插入b节点的右孩子为b1和c节点的左孩子为c1.";
this.richTextBox1.Text += "\n取c的左孩子: "+t.GetLeft("c").ToString();
this.richTextBox1.Text += "\n取b的右孩子: "+t.GetRight("b").ToString();
this.richTextBox1.Text += "\n取c1的双亲节点:"+t.GetParent("c1").ToString();
this.richTextBox1.Text += "\n中序遍历: ";
this.mprintTree(n);
t.DeleteLeft("c");
t.DeleteRight("b");
this.richTextBox1.Text += "\n删除b节点的右孩子b1和c节点的左孩子c1,现在应为e和f.";
this.richTextBox1.Text += "\n取c的左孩子: "+t.GetLeft("c").ToString();
this.richTextBox1.Text += "\n取b的右孩子: "+t.GetRight("b").ToString();
this.richTextBox1.Text += "\n中序遍历: ";
this.mprintTree(n);
/*
* test heap type opration
*/
this.richTextBox1.Text += "\n\n测试堆: ";
//The test data
int [] idata = new int[]{4,6, 3, 7,9,2,5,8,10,12,1};
string di = null;
string[] dp = new string[idata.Length];
for(int i=0; i<idata.Length; i++)
{
string sm = idata[i].ToString();
di += sm + ",";
dp[i] = sm;
}
this.richTextBox1.Text += "\n原始数据: "+ di;
heap hb = new heap();
hb.CreateHeap(dp,true); //create The heap of big tree
this.richTextBox1.Text += "\n大根堆前序遍历: ";
fprintTree(hb.HRoot);
heap hs = new heap();
hs.CreateHeap(dp,false); //create The heap of small tree
this.richTextBox1.Text += "\n小根堆前序遍历: ";
fprintTree(hs.HRoot);
heap ho = new heap();
ho.CreateHeap(s,false); //create The other type heap
this.richTextBox1.Text += "\n不是数值型的前序遍历: ";
fprintTree(ho.HRoot);
hs.InsertHeapLeft(22);
hb.InsertHeapRight(8);
this.richTextBox1.Text += "\n已在小根堆插入22,大根堆插入8.";
this.richTextBox1.Text += "\n取22的父节点: "+hs.GetHeapParent(22).ToString();
this.richTextBox1.Text += "\n取8的父节点: "+ hb.GetHeapParent(8).ToString();
this.richTextBox1.Text += "\n小根堆中序遍历: ";
this.mprintTree(hs.HRoot);
this.richTextBox1.Text += "\n大根堆中序遍历: ";
this.mprintTree(hb.HRoot);
//正在测试中,有些小问题
/*hs.DeleteRight(4);
hb.DeleteRight(8);
this.richTextBox1.Text += "\n删除了22和8.\n小根堆中序遍历: ";
this.mprintTree(hs.HRoot);
this.richTextBox1.Text += "\n大根堆中序遍历: ";
this.mprintTree(hb.HRoot);*/
}
private void fprintTree(treeNode n)
{
if(n != null)
{
this.richTextBox1.Text += n.Data+",";
fprintTree(n.Left);
fprintTree(n.Right);
}
}
private void mprintTree(treeNode n)
{
if(n != null)
{
mprintTree(n.Left);
this.richTextBox1.Text += n.Data+",";
mprintTree(n.Right);
}
}
private void bprintTree(treeNode n)
{
if(n != null)
{
bprintTree(n.Left);
bprintTree(n.Right);
this.richTextBox1.Text += n.Data+",";
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -