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

📄 form1.cs

📁 图的遍历
💻 CS
📖 第 1 页 / 共 2 页
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace WindowsApplication2
{
	/// <summary>
	/// Form1 的摘要说明。
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private int i=0;
		private Class1[] cl=new Class1[20];
		private bool[] vvisitied=new bool[20];
		private string[] NodeName=new string[20];
		private string[,] weight=new string[10,10];
		private string[] allvisit=new string[100];
		private int p=0,q=0,c=0,ssum=0;
		private int x,y;
		private double z;
        private AxShockwaveFlashObjects.AxShockwaveFlash LoadFlash;

		private System.Windows.Forms.TextBox textBox1;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.TextBox textBox3;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Button button2;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Button button3;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.ComboBox comboBox1;
		private System.Windows.Forms.Button button4;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.ComboBox comboBox2;
		private System.Windows.Forms.Label label7;
		private System.Windows.Forms.TextBox textBox4;
		private System.Windows.Forms.Button button7;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.GroupBox groupBox2;
		private System.Windows.Forms.GroupBox groupBox3;
		private System.Windows.Forms.Button button8;
		private System.Windows.Forms.GroupBox groupBox4;
		private System.Windows.Forms.Timer timer1;
		private System.Windows.Forms.Label label8;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Button button5;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Label label9;
		private System.ComponentModel.IContainer components;

		public Form1()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();
			this.LoadFlash.Movie= Application.StartupPath+"\\loading.swf";
			//
			// 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.components = new System.ComponentModel.Container();
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
			this.LoadFlash = new AxShockwaveFlashObjects.AxShockwaveFlash();
			this.textBox1 = new System.Windows.Forms.TextBox();
			this.label1 = new System.Windows.Forms.Label();
			this.textBox3 = new System.Windows.Forms.TextBox();
			this.button1 = new System.Windows.Forms.Button();
			this.button2 = new System.Windows.Forms.Button();
			this.label4 = new System.Windows.Forms.Label();
			this.button3 = new System.Windows.Forms.Button();
			this.label5 = new System.Windows.Forms.Label();
			this.comboBox1 = new System.Windows.Forms.ComboBox();
			this.button4 = new System.Windows.Forms.Button();
			this.label6 = new System.Windows.Forms.Label();
			this.comboBox2 = new System.Windows.Forms.ComboBox();
			this.label7 = new System.Windows.Forms.Label();
			this.textBox4 = new System.Windows.Forms.TextBox();
			this.button7 = new System.Windows.Forms.Button();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.button8 = new System.Windows.Forms.Button();
			this.groupBox2 = new System.Windows.Forms.GroupBox();
			this.groupBox3 = new System.Windows.Forms.GroupBox();
			this.label2 = new System.Windows.Forms.Label();
			this.groupBox4 = new System.Windows.Forms.GroupBox();
			this.button5 = new System.Windows.Forms.Button();
			this.timer1 = new System.Windows.Forms.Timer(this.components);
			this.label8 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.label9 = new System.Windows.Forms.Label();
			((System.ComponentModel.ISupportInitialize)(this.LoadFlash)).BeginInit();
			this.groupBox1.SuspendLayout();
			this.groupBox2.SuspendLayout();
			this.groupBox3.SuspendLayout();
			this.groupBox4.SuspendLayout();
			this.SuspendLayout();
			// 
			// LoadFlash
			// 
			this.LoadFlash.Enabled = true;
			this.LoadFlash.Location = new System.Drawing.Point(0, 0);
			this.LoadFlash.Name = "LoadFlash";
			this.LoadFlash.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("LoadFlash.OcxState")));
			this.LoadFlash.Size = new System.Drawing.Size(546, 407);
			this.LoadFlash.TabIndex = 9;
			// 
			// textBox1
			// 
			this.textBox1.Location = new System.Drawing.Point(168, 24);
			this.textBox1.Name = "textBox1";
			this.textBox1.Size = new System.Drawing.Size(64, 21);
			this.textBox1.TabIndex = 0;
			this.textBox1.Text = "";
			// 
			// label1
			// 
			this.label1.BackColor = System.Drawing.SystemColors.InactiveCaptionText;
			this.label1.Location = new System.Drawing.Point(48, 16);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(104, 16);
			this.label1.TabIndex = 1;
			this.label1.Text = "建立图的邻接表:";
			this.label1.Visible = false;
			// 
			// textBox3
			// 
			this.textBox3.Location = new System.Drawing.Point(144, 16);
			this.textBox3.Name = "textBox3";
			this.textBox3.Size = new System.Drawing.Size(256, 21);
			this.textBox3.TabIndex = 3;
			this.textBox3.Text = "";
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(64, 16);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(96, 32);
			this.button1.TabIndex = 6;
			this.button1.Text = "广度优先遍历";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// button2
			// 
			this.button2.Location = new System.Drawing.Point(256, 16);
			this.button2.Name = "button2";
			this.button2.Size = new System.Drawing.Size(96, 32);
			this.button2.TabIndex = 7;
			this.button2.Text = "深度优先遍历";
			this.button2.Click += new System.EventHandler(this.button2_Click);
			// 
			// label4
			// 
			this.label4.BackColor = System.Drawing.SystemColors.InactiveCaptionText;
			this.label4.Location = new System.Drawing.Point(72, 360);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(72, 20);
			this.label4.TabIndex = 8;
			this.label4.Text = "遍历结果:";
			this.label4.Visible = false;
			// 
			// button3
			// 
			this.button3.Location = new System.Drawing.Point(280, 24);
			this.button3.Name = "button3";
			this.button3.Size = new System.Drawing.Size(64, 24);
			this.button3.TabIndex = 9;
			this.button3.Text = "确定";
			this.button3.Click += new System.EventHandler(this.button3_Click);
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(8, 24);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(160, 24);
			this.label5.TabIndex = 10;
			this.label5.Text = "在此分别输入所有节点名:";
			// 
			// comboBox1
			// 
			this.comboBox1.Location = new System.Drawing.Point(72, 24);
			this.comboBox1.Name = "comboBox1";
			this.comboBox1.Size = new System.Drawing.Size(48, 20);
			this.comboBox1.TabIndex = 11;
			// 
			// button4
			// 
			this.button4.Location = new System.Drawing.Point(280, 24);
			this.button4.Name = "button4";
			this.button4.Size = new System.Drawing.Size(64, 24);
			this.button4.TabIndex = 13;
			this.button4.Text = "确定";
			this.button4.Click += new System.EventHandler(this.button4_Click);
			// 
			// label6
			// 
			this.label6.Location = new System.Drawing.Point(8, 24);
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(72, 16);
			this.label6.TabIndex = 14;
			this.label6.Text = "节点连接:";
			// 
			// comboBox2
			// 
			this.comboBox2.Location = new System.Drawing.Point(120, 24);
			this.comboBox2.Name = "comboBox2";
			this.comboBox2.Size = new System.Drawing.Size(48, 20);
			this.comboBox2.TabIndex = 15;
			// 
			// label7
			// 
			this.label7.Location = new System.Drawing.Point(168, 24);
			this.label7.Name = "label7";
			this.label7.Size = new System.Drawing.Size(72, 16);
			this.label7.TabIndex = 16;
			this.label7.Text = "弧的权值:";
			// 
			// textBox4
			// 
			this.textBox4.Enabled = false;
			this.textBox4.Location = new System.Drawing.Point(232, 24);
			this.textBox4.Name = "textBox4";
			this.textBox4.Size = new System.Drawing.Size(40, 21);
			this.textBox4.TabIndex = 17;
			this.textBox4.Text = "1";
			// 
			// button7
			// 
			this.button7.Enabled = false;
			this.button7.Location = new System.Drawing.Point(352, 24);
			this.button7.Name = "button7";
			this.button7.Size = new System.Drawing.Size(64, 24);
			this.button7.TabIndex = 20;
			this.button7.Text = "完成";
			this.button7.Click += new System.EventHandler(this.button7_Click);
			// 
			// groupBox1
			// 
			this.groupBox1.BackColor = System.Drawing.SystemColors.InactiveCaptionText;
			this.groupBox1.Controls.Add(this.button8);
			this.groupBox1.Controls.Add(this.textBox4);
			this.groupBox1.Controls.Add(this.comboBox1);
			this.groupBox1.Controls.Add(this.label6);
			this.groupBox1.Controls.Add(this.comboBox2);
			this.groupBox1.Controls.Add(this.label7);
			this.groupBox1.Controls.Add(this.button4);
			this.groupBox1.Enabled = false;
			this.groupBox1.Location = new System.Drawing.Point(48, 96);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(424, 56);
			this.groupBox1.TabIndex = 21;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "连接";
			this.groupBox1.Visible = false;
			// 
			// button8
			// 
			this.button8.Location = new System.Drawing.Point(352, 24);
			this.button8.Name = "button8";
			this.button8.Size = new System.Drawing.Size(64, 24);
			this.button8.TabIndex = 18;
			this.button8.Text = "完成";
			this.button8.Click += new System.EventHandler(this.button8_Click);
			// 
			// groupBox2
			// 
			this.groupBox2.BackColor = System.Drawing.SystemColors.InactiveCaptionText;
			this.groupBox2.Controls.Add(this.label5);
			this.groupBox2.Controls.Add(this.textBox1);
			this.groupBox2.Controls.Add(this.button3);
			this.groupBox2.Controls.Add(this.button7);
			this.groupBox2.Location = new System.Drawing.Point(48, 32);
			this.groupBox2.Name = "groupBox2";
			this.groupBox2.Size = new System.Drawing.Size(424, 56);
			this.groupBox2.TabIndex = 22;
			this.groupBox2.TabStop = false;
			this.groupBox2.Text = "节点名";
			this.groupBox2.Visible = false;
			// 
			// groupBox3
			// 
			this.groupBox3.BackColor = System.Drawing.SystemColors.InactiveCaptionText;
			this.groupBox3.Controls.Add(this.label2);
			this.groupBox3.Controls.Add(this.textBox3);
			this.groupBox3.Location = new System.Drawing.Point(48, 224);
			this.groupBox3.Name = "groupBox3";
			this.groupBox3.Size = new System.Drawing.Size(424, 48);
			this.groupBox3.TabIndex = 23;
			this.groupBox3.TabStop = false;
			this.groupBox3.Text = "栈/队列";
			this.groupBox3.Visible = false;
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(16, 24);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(128, 16);
			this.label2.TabIndex = 4;
			this.label2.Text = "栈/队列的出入情况:";
			// 
			// groupBox4
			// 
			this.groupBox4.BackColor = System.Drawing.SystemColors.InactiveCaptionText;
			this.groupBox4.Controls.Add(this.button5);
			this.groupBox4.Controls.Add(this.button1);
			this.groupBox4.Controls.Add(this.button2);
			this.groupBox4.Location = new System.Drawing.Point(48, 296);
			this.groupBox4.Name = "groupBox4";
			this.groupBox4.Size = new System.Drawing.Size(424, 56);
			this.groupBox4.TabIndex = 24;
			this.groupBox4.TabStop = false;
			this.groupBox4.Text = "操作";
			this.groupBox4.Visible = false;
			// 
			// button5
			// 
			this.button5.Enabled = false;
			this.button5.Location = new System.Drawing.Point(160, 24);
			this.button5.Name = "button5";
			this.button5.Size = new System.Drawing.Size(96, 24);
			this.button5.TabIndex = 8;
			this.button5.Text = "最小生成树";
			this.button5.Click += new System.EventHandler(this.button5_Click);
			// 
			// timer1
			// 
			this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
			// 
			// label8
			// 
			this.label8.BackColor = System.Drawing.SystemColors.InactiveCaptionText;
			this.label8.Location = new System.Drawing.Point(144, 360);
			this.label8.Name = "label8";
			this.label8.Size = new System.Drawing.Size(328, 20);
			this.label8.TabIndex = 25;
			this.label8.Visible = false;
			// 
			// label3
			// 
			this.label3.BackColor = System.Drawing.SystemColors.InactiveCaptionText;
			this.label3.Location = new System.Drawing.Point(152, 384);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(320, 16);
			this.label3.TabIndex = 26;
			this.label3.Visible = false;
			// 
			// label9
			// 
			this.label9.BackColor = System.Drawing.SystemColors.InactiveCaptionText;
			this.label9.Location = new System.Drawing.Point(72, 384);
			this.label9.Name = "label9";
			this.label9.Size = new System.Drawing.Size(80, 16);
			this.label9.TabIndex = 27;
			this.label9.Text = "最小生成树:";
			this.label9.Visible = false;
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.BackColor = System.Drawing.SystemColors.Control;
			this.ClientSize = new System.Drawing.Size(546, 407);
			this.Controls.Add(this.label9);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.label8);
			this.Controls.Add(this.groupBox4);
			this.Controls.Add(this.groupBox3);
			this.Controls.Add(this.groupBox2);
			this.Controls.Add(this.groupBox1);
			this.Controls.Add(this.label4);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.LoadFlash);
			this.MaximizeBox = false;
			this.Name = "Form1";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "图的遍历";
			this.Load += new System.EventHandler(this.Form1_Load);
			((System.ComponentModel.ISupportInitialize)(this.LoadFlash)).EndInit();
			this.groupBox1.ResumeLayout(false);
			this.groupBox2.ResumeLayout(false);
			this.groupBox3.ResumeLayout(false);
			this.groupBox4.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

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

		private void button3_Click(object sender, System.EventArgs e)
		{
			if (this.textBox1.Text=="")
				MessageBox.Show("节点名不能为空!");
			else
			{
				NodeName[i]=this.textBox1.Text;
				if ((bool)check(NodeName[i]))
				{
					cl[i]=new Class1(NodeName[i]);
					this.i=this.i+1;
					MessageBox.Show("请输入下一个节点名,若所有节点名已输完,按“完成”","输入成功",MessageBoxButtons.OK,MessageBoxIcon.Information);
					this.button7.Enabled=true;
					this.textBox1.Text="";
					
				}
				else
				{
					MessageBox.Show("此节点名已存在,请重新输入","错误",MessageBoxButtons.OK,MessageBoxIcon.Warning);
				}
			}
		}

		private void button7_Click(object sender, System.EventArgs e)
		{
			for (x=0;x<10;x++)
				for(y=0;y<10;y++)
				{
					this.weight[x,y]="0";
				}
			this.groupBox2.Enabled=false;
			this.groupBox1.Enabled=true;
			for (int j=0;j<i;j++)
			{
				this.comboBox1.Items.Add(cl[j].NodeName);
				this.comboBox2.Items.Add(cl[j].NodeName);
			}
			if (MessageBox.Show("您将要创建的无向图是带权图吗?","导向",MessageBoxButtons.YesNo,MessageBoxIcon.Question)==DialogResult.Yes)
			{
				this.textBox4.Enabled=true;
				this.textBox4.Text="";
				this.button5.Enabled=true;
			}
		}

		
		private bool check(string IsDifferent)
		{
			if (i==0)
			{

⌨️ 快捷键说明

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