Guest User

Untitled

a guest
Nov 16th, 2015
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.01 KB | None | 0 0
  1. static final int ArraySize = 6;
  2.  
  3.     static int Size; // Размер матрицы, считываем с консоли
  4.     static int MaxWeight; // Размер максимального пути, считываем с консоли
  5.     static Random rand = new Random();
  6.     static int MinLong = 10000; // Максимальное расстояние между городами
  7.     static int step; // Шаг алгоритма или на какую вершину мы переходим
  8.     static int count = 0; // Счётчик
  9.     static int path = 0;  // Сумма пути
  10.  
  11.  
  12.     static int[][] MapArray = new int[ArraySize][ArraySize]; // Граф смежности
  13.     static boolean[] Visited = new boolean[ArraySize]; // Массив пройденных вершин
  14.     static int[] Way = new int[ArraySize]; // Массив пройденных вершин
  15.  
  16.     public static void MainMethod(int CurrentVertex) {
  17.         Visited[CurrentVertex] = true;
  18.         for(int j = 0; j < Size; j++) {
  19.             if ( (MapArray[CurrentVertex][j] != 0) && (!Visited[j]) ) {
  20.                 if (MapArray[CurrentVertex][j] < MinLong) {
  21.                     MinLong = MapArray[CurrentVertex][j];
  22.                     step = j;
  23.                 }
  24.                 count++;
  25. //                Way[CurrentVertex] = step; // Записываем в массив путь из вершин
  26. //                path = path + MapArray[CurrentVertex][step];  // Записываем сумму пути
  27.             }
  28.             path = path + MapArray[CurrentVertex][step];  // Записываем сумму пути
  29.             Way[CurrentVertex] = step; // Записываем в массив путь из вершин
  30.             if (count == (Size)) { // Прошли по всем вершинам
  31.                 path = path + MapArray[step][0]; // Записываем путь из предпоследней вершины, в последнюю
  32.             }
  33.             MainMethod(CurrentVertex);
  34.         }
  35.     }
Advertisement
Add Comment
Please, Sign In to add comment