Advertisement
Guest User

Untitled

a guest
Nov 29th, 2015
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.18 KB | None | 0 0
  1.  public void SearchTrack(int first, int second)
  2.         {
  3.             bool[] A = new bool[graph1.Counter];
  4.             int[] B = new int[graph1.Counter];
  5.             int[] C = new int[graph1.Counter];
  6.             for (int i = 0; i < graph1.Counter;i++ )
  7.             {
  8.                 A[i] = false;
  9.                 B[i] = Int32.MaxValue;
  10.                 C[i] = first;
  11.             }
  12.             A[first] = true;
  13.             B[first] = 0;
  14.             C[first] = -1;
  15.             int current=first;
  16.             while (1==1)
  17.             {
  18.                 foreach(Couple tmp in graph1.GetCCircle(current).Neighbours)
  19.                 {
  20.                    // MessageBox.Show((current + 1).ToString() + " -> " + (tmp.Kuda+1).ToString());
  21.                     if(B[tmp.Kuda]>B[current]+tmp.Skolko&&!A[tmp.Kuda])
  22.                     {
  23.                        
  24.                         B[tmp.Kuda] = B[current] + tmp.Skolko;
  25.                         C[tmp.Kuda] = current;
  26.                     }
  27.                 }
  28.                 int min = Int32.MaxValue;
  29.                 int imin = -1;
  30.                 for (int i = 0; i < graph1.Counter;i++ )
  31.                 {
  32.                     if(B[i]<min&&!A[i])
  33.                     {
  34.                         min = B[i];
  35.                         imin = i;
  36.                     }
  37.                 }
  38.                 if(imin==-1)
  39.                 {
  40.                     MessageBox.Show("А пути похоже что и нет!");
  41.                     return;
  42.                 }
  43.                 else
  44.                 {
  45.                     current = imin;
  46.                     A[current] = true;
  47.                   //  MessageBox.Show("Текущая вершина " + (current + 1).ToString());
  48.                 }
  49.                 if(A[second])
  50.                 {
  51.                     break;
  52.                 }
  53.             }
  54.             label1.Text = B[second].ToString();
  55.             label2.Text="";
  56.             int track=second;
  57.             while (track!=first)
  58.             {
  59.  
  60.                 label2.Text += (track+1).ToString() + " -> ";
  61.                 track = C[track];
  62.             }
  63.             label2.Text += (first+1).ToString()/*.Reverse()*/;
  64.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement