开发者

print output for each value of i,j

in the code below that belongs to floyd algorithm how can i print the output for each value of i,j?for example shortest distance of [0,0]=2 and shortest [0,1]=4 etc now it prints shortest distance from i to j is:3(for example)

private void button10_Click(obj开发者_如何学JAVAect 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);

          }
       }
   }


i edited both of the MessageBox.show() to this form and it corrected:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜