-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGRAPH.java
More file actions
139 lines (125 loc) · 3.11 KB
/
GRAPH.java
File metadata and controls
139 lines (125 loc) · 3.11 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
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import java.util.Vector;
import java.util.Iterator;
public class GRAPH<E>
{
NODE<E> source;
public GRAPH(NODE<E> n)
{
source = n;
}
public int nbMin()
{
return source.nbPuitMin(source);
}
public int nbMax()
{
return source.nbPuitMax(source);
}
public void aff()
{
Vector<E> res = new Vector<E>();
int i;
source.affProf(source,res);
for (i=0; i<res.size() - 1; i++)
System.out.print(res.get(i) + ", ");
System.out.println(res.get(i));
}
public void affLgr(Vector<NODE<E>> n, Vector<NODE<E>> res)
{
Vector<NODE<E>> next_node = new Vector<NODE<E>>();
Iterator<NODE<E>> it = n.iterator();
boolean put_brackets = false;
boolean put_space = false;
while (it.hasNext())
{
NODE<E> node = it.next();
if (!res.contains(node))
{
if(!put_brackets)
{
put_brackets = true;
System.out.print("(");
}
if (put_space)
System.out.print(", ");
else
put_space = true;
System.out.print(node.val);
res.add(node);
}
Vector<NODE<E>> tab = node.succ;
Iterator<NODE<E>> it2 = tab.iterator();
while (it2.hasNext())
{
NODE<E> node2 = it2.next();
next_node.add(node2);
}
}
if (put_brackets)
System.out.print(")");
if(!next_node.isEmpty())
{
if (put_brackets)
System.out.print(", ");
affLgr(next_node, res);
}
}
public void afg()
{
Vector<NODE<E>> res = new Vector<NODE<E>>();
Vector<NODE<E>> n = new Vector<NODE<E>>();
n.add(source);
affLgr(n,res);
}
public static void main(String[] args)
{
GRAPH<Integer> g;
NODE<Integer> n1, n2, n3, n4, n5, n6, n7, n8, n9, n10, n11, n12, n13, n14;
NODE<Integer> n15, n16;
n1 = new NODE<Integer>(1);
n2 = new NODE<Integer>(2);
n3 = new NODE<Integer>(3);
n4 = new NODE<Integer>(4);
n5 = new NODE<Integer>(5);
n6 = new NODE<Integer>(6);
n7 = new NODE<Integer>(7);
n8 = new NODE<Integer>(8);
n9 = new NODE<Integer>(9);
n10 = new NODE<Integer>(10);
n11 = new NODE<Integer>(11);
n12 = new NODE<Integer>(12);
n13 = new NODE<Integer>(13);
n14 = new NODE<Integer>(14);
n15 = new NODE<Integer>(15);
n16 = new NODE<Integer>(16);
g = new GRAPH<Integer>(n1);
n1.adjNoeud(n2);
n2.adjNoeud(n9);
n9.adjNoeud(n14);
n14.adjNoeud(n15);
n15.adjNoeud(n16);
n2.adjNoeud(n5);
n5.adjNoeud(n6);
n6.adjNoeud(n8);
n8.adjNoeud(n9);
n8.adjNoeud(n15);
n6.adjNoeud(n10);
n6.adjNoeud(n7);
n7.adjNoeud(n11);
n11.adjNoeud(n10);
n11.adjNoeud(n12);
n12.adjNoeud(n13);
n13.adjNoeud(n16);
n1.adjNoeud(n3);
n3.adjNoeud(n7);
n1.adjNoeud(n7);
n1.adjNoeud(n4);
n4.adjNoeud(n11);
System.out.println("Chemin le plus court = " + g.nbMin());
System.out.println("Chemin le plus long = " + g.nbMax());
System.out.print("parcours en profondeur : ");
g.aff();
System.out.print("parcours en largeur : ");
g.afg();
}
}