forked from Slashgear/polytech-isi3-tp1-graph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGraph.java
executable file
·94 lines (64 loc) · 1.46 KB
/
Graph.java
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package graph;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Graph implements IDirectedGraph {
/**
* A chaque cle=noeud est associe la liste des arcs sortants de ce noeud
*/
private Map<Node,List<Arc>> adjacence;
public Graph(){
adjacence = new HashMap<Node,List<Arc>>();
}
/**
*
* @param _n1
* @param _n2
* @return vrai si graph possede arc de src _n1 et destination _n2
*/
public boolean hasArc(Node _n1, Node _n2){
List<Arc> arretesAdj = adjacence.get(_n1);
for (Arc _a : arretesAdj){
if (_n1.equals(_a.getSource()) && _n2.equals(_a.getDestination()))
return true;
}
return false;
}
public void addNode(Node _node){
adjacence.put(_node, new ArrayList<Arc>());
}
public void addArc(Arc _edge){
if (!hasArc(_edge.getSource(),_edge.getDestination()))
adjacence.get(_edge.getSource()).add(_edge);
}
public List<Node> getAllNodes(){
//A COMPLETER
return null;
}
public int getNbNodes(){
//A COMPLETER
return 0;
}
/**
*
* @param _n
* @return tous les arcs de source _n
*/
public List<Arc> getArc(Node _n){
return adjacence.get(_n);
}
/**
* renvoie tous les noeuds qui sont destination d'un arc dont la source est _n
*/
public List<Node> getAdjNodes(Node _n){
//A COMPLETER
return null;
}
@Override
public String toString() {
String s="Graph \n";
//A COMPLETER
return s;
}
}