En VB .Net son 2 lineas.
Cuantas te llevó en java?
O sino lo sacas del framework directamente... está en System.Dijkstra.Elmasfacil
Saludos,
AiZ![]()
El otro día me puse a investigar este algoritmo... hice la implementación en java.. quedo linda
Código:package com.cumbianena.dijkstra; public class DijkstraEngine { public int[] execute(int[][] graph, int node) { final boolean settledNodes[] = new boolean[graph.length]; final int shortestDistances[] = new int[graph.length]; settledNodes[0] = true; for (int i = 1; i < shortestDistances.length; i++) { if (graph[node][i] != 0) shortestDistances[i] = graph[node][i]; else shortestDistances[i] = Integer.MAX_VALUE; } for (int i = 0; i < (shortestDistances.length - 1); i++){ final int next = minVertex(shortestDistances, settledNodes); settledNodes[next] = true; for (int j = 0; j < graph[0].length; j++) { final int d = shortestDistances[next] + graph[next][j]; if ( shortestDistances[j] > d) shortestDistances[j] = shortestDistances[next] + graph[next][j]; } } return shortestDistances; } private static int minVertex (int [] shortestDistances, boolean [] settledNodes) { int x = Integer.MAX_VALUE; int y = -1; for (int i = 0; i < shortestDistances.length; i++) { if (!settledNodes[i] && shortestDistances[i] < x) { y = i; x = shortestDistances[i]; } } return y; } }
jejeje salutes
En VB .Net son 2 lineas.
Cuantas te llevó en java?
O sino lo sacas del framework directamente... está en System.Dijkstra.Elmasfacil
Saludos,
AiZ![]()
Por eso no me gusta .NET, me gusta hacer las cosas solito. No que me digan como hacerlo![]()
Fijate de tratar de no hacerlo objetoso, a ver si java no te dice como hacerlo entonces! (?)
(Btw, im against .net)
Actualmente hay 1 usuarios viendo este tema. (0 miembros y 1 visitantes)
Marcadores