在接受该程序的输入时遇到问题。还有,不知道怎么填那些空白的功能textBox1_TextChanged
,textBox9_TextChanged
。Form1_Load
.还有这些是什么;(object sender, EventArgs e)
? 帮助将不胜感激!这是我在 c# 中经验最少的情况下能走多远。
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 Floyd_Warshall
{
public partial class Form1 : Form
{
string ab="";
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void textBox9_TextChanged(object sender, EventArgs e)
{
ab = textBox9.Text;
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void button10_Click(object sender, EventArgs e)
{
int matrixDimention = Convert.ToInt32(ab);
int[,] intValues = new int[matrixDimention, matrixDimention];
string[] splitValues = textBox1.Text.Split(',');
int[,] pathS = new int[matrixDimention, matrixDimention];
for (int i = 0; i < splitValues.Length; i++)
{
intValues[i / (matrixDimention), i % (matrixDimention)] = Convert.ToInt32(splitValues[i]);
pathS[i / (matrixDimention), i % (matrixDimention)] = -1;
}
string displayString = "";
for (int inner = 0; inner < intValues.GetLength(0); inner++)
{
for (int outer = 0; outer < intValues.GetLength(0); outer++)
displayString += String.Format("{0}\t", intValues[inner, outer]);
displayString += Environment.NewLine;
}
int n = (int)Math.Pow(matrixDimention, 2);
string strn = n.ToString();
MessageBox.Show("matrix" + strn + "in" + strn + "is\n\n\n" + displayString);
for (int k = 1; k < n+1; k++)
for (int i = 1; i < n+1; i++)
for (int j = 1; j < n+1; j++)
if (intValues[i, j] > intValues[i, k] + intValues[k, j]){
intValues[i, j] = intValues[i, k] + intValues[k, j];
pathS[i,j] = k;
string str_intvalues = intValues[i, j].ToString();
MessageBox.Show("Shortest Path from i to j is: " + str_intvalues);
}
else{
string str_intvalues = intValues[i, j].ToString();
MessageBox.Show("Shortest Path from i to j is: " + str_intvalues);
}
}
}
}