-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
39 lines (37 loc) · 1.64 KB
/
Copy pathMain.java
File metadata and controls
39 lines (37 loc) · 1.64 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
// Gabriel Carraro Salzedas - 16827905
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
GrafoListaAdjacencia gL = new GrafoListaAdjacencia();
GrafoMatrizAdjacencia gM = new GrafoMatrizAdjacencia();
GrafoPonderadoMatrizAdjacencia gP = new GrafoPonderadoMatrizAdjacencia();
Scanner sc = new Scanner(System.in);
while (sc.hasNextLine()) {
String[] cmd = sc.nextLine().split(" ");
if (cmd[0].equals("i")) {
String v1 = cmd[1], v2 = cmd[2];
int peso = Integer.parseInt(cmd[3]);
for (Grafo g : new Grafo[]{gL, gM, gP}) g.adicionarVertice(v1);
for (Grafo g : new Grafo[]{gL, gM, gP}) g.adicionarVertice(v2);
gL.adicionarAresta(v1, v2);
gM.adicionarAresta(v1, v2);
gP.adicionarAresta(v1, v2, peso);
} else if (cmd[0].equals("d")) {
if (cmd.length == 3) {
gL.removerAresta(cmd[1], cmd[2]);
gM.removerAresta(cmd[1], cmd[2]);
gP.removerAresta(cmd[1], cmd[2]);
} else {
gL.removerVertice(cmd[1]);
gM.removerVertice(cmd[1]);
gP.removerVertice(cmd[1]);
}
} else if (cmd[0].equals("p")) {
System.out.println("Lista de Adjacencia\n" + gL.toString());
System.out.println("Matriz de Adjacencia\n" + gM.toString());
System.out.println("Ponderado - Matriz de Adjacencia\n" + gP.toString());
}
}
sc.close();
}
}