私は以下に書いたコードにDijkstrasアルゴリズムを書こうとしています。しかし、私はこれをやり始める方法がわかりません。私はそれをオンラインソースから少し見直しましたが、私はそれを実際に動作させる方法はまだ分かりません。私はそれを評価経路法に入れることを好む。メニューオプションでこのメソッドを呼び出すと、ソートアルゴリズムが実行されます。Dijkstraのアルゴリズムを書くのに助けが必要
FYI。私は、都市Aから都市Bまでの最短経路をマイルと価格で並べ替えています。
以下は私のコードです。シアトルからサンフランシスコへ
import java.io.*;
import java.util.*;
public class CityCalcultor {
static LinkedList<String> cities = new LinkedList<String>();
static LinkedList<Integer> distance = new LinkedList<Integer>();
static LinkedList<Integer> price = new LinkedList<Integer>();
public static void main(String[] args)throws IOException
{
Scanner input = new Scanner(System.in);
String text;
int option = 0;
while (true)
{
System.out.println("\nWhat would you like to do:\n" +
"1. Add a city to the system\n" +
"2. Add a path to the system\n" +
"3. Evalute paths\n" +
"4. Exit\n" + "Your option: ");
text = input.nextLine();
option = Integer.parseInt(text);
switch (option)
{
case 1: EnterCity(); break;
case 2: EnterPath(); break;
case 3: EvalutePaths(); break;
case 4: return;
default: System.out.println("ERROR INVALID INPUT");
}
}
}
public static void EnterCity(){
String c = "";
LinkedList<String> cities = new LinkedList<String>(Arrays.asList(c));
Scanner City = new Scanner(System.in);
System.out.println("Please enter the city name ");
c = City.nextLine();
cities.add(c);
System.out.println("City " + c + " has been added ");
}
public static void EnterPath(){
Scanner Path = new Scanner(System.in);
int d = 0; int p = 0;
System.out.println("Enter the starting city ");
System.out.println();
System.out.println(Path.nextLine());
System.out.println("Enter the ending city ");
System.out.println(Path.nextLine());
System.out.println("Enter the distance between the two cities ");
d= Path.nextInt();
distance.add(d);
System.out.println("Enter the price between the two cities ");
p = Path.nextInt();
price.add(p);
System.out.println("The route was sucessfully added ");
}
private static void EvalutePaths(){
}
}
出力はなりますよう::
最短ルートは1290マイルです。私ができる場合は、ここで
具体的に何が役立ちますか?アルゴリズムのどの部分を理解するのが最も困っていますか? – templatetypedef
私はプログラムを見ましたが、Djikstraのものはありませんでした:(DjikstraのものとA *の両方について、Wikipediaはまともな記事としてWikipediaには2つの*別々の部分があります:1)データ(プログラムが何を集めているか)テスト用の静的データの配列と、2)最短パスアルゴリズムを使用します。 *それらを別々に保つ。 (そして、「本当の質問ではありません」;-) –
私は、配列からアルゴリズムにデータを渡す方法を理解するのに苦労しています。私は完全に最初から最後までアルゴリズムと混同しています。 – allencoded