-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLista.java
More file actions
38 lines (33 loc) · 1.01 KB
/
Lista.java
File metadata and controls
38 lines (33 loc) · 1.01 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
package java.grafo;
public class Lista {
int no; //No de origem
Vizinho prox_viz; //java.grafo.Lista encadeada vizinhos
Lista prox_no; //java.grafo.Lista encadeada nos
Lista(int c){ //Construtor
no = c;
prox_viz = null;
prox_no = null;
}
Vizinho pertence(int no){ //Testa se o no é vizinho e esta na lista encadeada de vizinhos
Vizinho resp = prox_viz;
while((resp != null) && (no != resp.no_viz))
resp = resp.prox;
return resp;
}
void ins_Viz(int c){ //Insere no na primeira posição da lista encadeada de vizinhos
Vizinho v = pertence(c);
if(v != null) return;
v = new Vizinho(c);
v.prox = prox_viz;
prox_viz = v;
}
public String toString(){
String resp = no + "(" + "): \n";
Vizinho p = prox_viz;
while(p != null){
resp += p.toString();
p = p.prox;
}
return resp + "\n";
}
}