Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void SearchTrack(int first, int second)
- {
- bool[] A = new bool[graph1.Counter];
- int[] B = new int[graph1.Counter];
- int[] C = new int[graph1.Counter];
- for (int i = 0; i < graph1.Counter;i++ )
- {
- A[i] = false;
- B[i] = Int32.MaxValue;
- C[i] = first;
- }
- A[first] = true;
- B[first] = 0;
- C[first] = -1;
- int current=first;
- while (1==1)
- {
- foreach(Couple tmp in graph1.GetCCircle(current).Neighbours)
- {
- // MessageBox.Show((current + 1).ToString() + " -> " + (tmp.Kuda+1).ToString());
- if(B[tmp.Kuda]>B[current]+tmp.Skolko&&!A[tmp.Kuda])
- {
- B[tmp.Kuda] = B[current] + tmp.Skolko;
- C[tmp.Kuda] = current;
- }
- }
- int min = Int32.MaxValue;
- int imin = -1;
- for (int i = 0; i < graph1.Counter;i++ )
- {
- if(B[i]<min&&!A[i])
- {
- min = B[i];
- imin = i;
- }
- }
- if(imin==-1)
- {
- MessageBox.Show("А пути похоже что и нет!");
- return;
- }
- else
- {
- current = imin;
- A[current] = true;
- // MessageBox.Show("Текущая вершина " + (current + 1).ToString());
- }
- if(A[second])
- {
- break;
- }
- }
- label1.Text = B[second].ToString();
- label2.Text="";
- int track=second;
- while (track!=first)
- {
- label2.Text += (track+1).ToString() + " -> ";
- track = C[track];
- }
- label2.Text += (first+1).ToString()/*.Reverse()*/;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement