打印输出i,j的每个值

时间:2010-12-24 16:25:21

标签: c# winforms algorithm

在下面的代码中属于floyd算法我如何打印i,j?的每个值的输出,例如[0,0] = 2和最短[0,1] = 4等的最短距离 现在它打印从i到j的最短距离是:3(例如)

private void button10_Click(object sender, EventArgs e)
{

  string ab = textBox11.Text;
  int matrixDimention = Convert.ToInt32(ab);
  int[,] intValues = new int[matrixDimention, matrixDimention];
  string[] splitValues = textBox9.Text.Split(',');

  for (int i = 0; i < splitValues.Length; i++)
    intValues[i / (matrixDimention), i % (matrixDimention)] = Convert.ToInt32(splitValues[i]);

  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=matrixDimension

  MessageBox.Show("matrix"+strn+ "in" + strn + "is\n\n\n" +displayString);

  ////before this line i wrote the codes to get the numbers that user enter in textbox and put it in an 2d array
  for (int k = 0; k < n; k++)
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
        {
          if (intValues[i, j] > intValues[i, k] + intValues[k, j])
          {
                intValues[i, j] = intValues[i, k] + intValues[k, j];
                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);

          }
       }
   }

1 个答案:

答案 0 :(得分:2)

我将两个MessageBox.show()编辑到此表单并更正:

MessageBox.Show("Shortest distance from" + i + " to " + j + " isnnt: " + str_intvalues);