-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGrafo.java
More file actions
39 lines (36 loc) · 974 Bytes
/
Grafo.java
File metadata and controls
39 lines (36 loc) · 974 Bytes
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
package java.grafo;
public class Grafo {
Lista prim;
Grafo(){ prim = null; }
Lista pertence(int no){ //Ve se um no esta no grafo
Lista resp = prim;
while((resp != null) && (no != resp.no)) resp = resp.prox_no;
return resp;
}
void insere(int no){ //Insere no no grafo
Lista p = pertence(no);
if(p == null){
p = new Lista(no);
Lista q = prim;
if(q == null){
prim = p;
return;
}
while(q.prox_no != null) q = q.prox_no;
q.prox_no = p;
}
}
void insere(int no1, int no2){ //Insere conexao
Lista p = pertence(no1);
p.ins_Viz(no2);
}
public String toString(){
String resp = "";
Lista p = prim;
while(p != null){
resp += p.toString();
p = p.prox_no;
}
return resp;
}
}