-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
executable file
·40 lines (38 loc) · 1.66 KB
/
Main.java
File metadata and controls
executable file
·40 lines (38 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package com.company;
import java.util.Scanner;
import static java.lang.System.exit;
public class Main {
public static void main(String[] args) {
Dijkstra_algo dijkstra = new Dijkstra_algo();
Prim prim = new Prim();
while (true) {
System.out.println("\n*************Enter Your Adjacency matrix graph**************\n");
Scanner input = new Scanner(System.in);
System.out.println("Enter number of nodes : ");
int nodes = input.nextInt();
int rows = nodes;
int columns = nodes;
int adjacency_matrix[][] = new int[rows][columns];
for (int i = 0; i < adjacency_matrix.length; i++) {
System.out.printf("Enter %d integers for row %d/%d (delimeted by spaces): \n",
columns, i + 1, rows);
for (int j = 0; j < adjacency_matrix[i].length; j++)
adjacency_matrix[i][j] = input.nextInt();
}
System.out.println("Enter Your choice : \n(1)MST prim's algorithm\n(2)Shortest path Dijkstra algorithm\n(3)Termninate program");
int choice = input.nextInt();
switch (choice){
case 1:
prim.prim_algo(adjacency_matrix);
break;
case 2:
System.out.println("You choose dijkstra shortest path algorithm\nEnter Your start node : ");
int start = input.nextInt();
dijkstra.dijkstra_algo(adjacency_matrix,start);
break;
case 3:
exit(0);
}
}
}
}