@@ -31,8 +31,7 @@ public static List<Integer> findTreeCenters(List<List<Integer>> tree) {
31
31
32
32
int processedLeafs = leaves .size ();
33
33
34
- // Remove leaf nodes and decrease the degree of
35
- // each node adding new leaf nodes progressively
34
+ // Remove leaf nodes and decrease the degree of each node adding new leaf nodes progressively
36
35
// until only the centers remain.
37
36
while (processedLeafs < n ) {
38
37
List <Integer > newLeaves = new ArrayList <>();
@@ -78,29 +77,29 @@ public static void main(String[] args) {
78
77
addUndirectedEdge (graph , 6 , 8 );
79
78
80
79
// Centers are 2
81
- System .out .println (findTreeCenters (graph ) + " \n " );
80
+ System .out .println (findTreeCenters (graph ));
82
81
83
82
// Centers are 0
84
83
List <List <Integer >> graph2 = createEmptyTree (1 );
85
- System .out .println (findTreeCenters (graph2 ) + " \n " );
84
+ System .out .println (findTreeCenters (graph2 ));
86
85
87
86
// Centers are 0,1
88
87
List <List <Integer >> graph3 = createEmptyTree (2 );
89
88
addUndirectedEdge (graph3 , 0 , 1 );
90
- System .out .println (findTreeCenters (graph3 ) + " \n " );
89
+ System .out .println (findTreeCenters (graph3 ));
91
90
92
91
// Centers are 1
93
92
List <List <Integer >> graph4 = createEmptyTree (3 );
94
93
addUndirectedEdge (graph4 , 0 , 1 );
95
94
addUndirectedEdge (graph4 , 1 , 2 );
96
- System .out .println (findTreeCenters (graph4 ) + " \n " );
95
+ System .out .println (findTreeCenters (graph4 ));
97
96
98
97
// Centers are 1,2
99
98
List <List <Integer >> graph5 = createEmptyTree (4 );
100
99
addUndirectedEdge (graph5 , 0 , 1 );
101
100
addUndirectedEdge (graph5 , 1 , 2 );
102
101
addUndirectedEdge (graph5 , 2 , 3 );
103
- System .out .println (findTreeCenters (graph5 ) + " \n " );
102
+ System .out .println (findTreeCenters (graph5 ));
104
103
105
104
// Centers are 2,3
106
105
List <List <Integer >> graph6 = createEmptyTree (7 );
@@ -110,6 +109,6 @@ public static void main(String[] args) {
110
109
addUndirectedEdge (graph6 , 3 , 4 );
111
110
addUndirectedEdge (graph6 , 4 , 5 );
112
111
addUndirectedEdge (graph6 , 4 , 6 );
113
- System .out .println (findTreeCenters (graph6 ) + " \n " );
112
+ System .out .println (findTreeCenters (graph6 ));
114
113
}
115
114
}
0 commit comments