@@ -31,8 +31,7 @@ public static List<Integer> findTreeCenters(List<List<Integer>> tree) {
3131
3232 int processedLeafs = leaves .size ();
3333
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
3635 // until only the centers remain.
3736 while (processedLeafs < n ) {
3837 List <Integer > newLeaves = new ArrayList <>();
@@ -78,29 +77,29 @@ public static void main(String[] args) {
7877 addUndirectedEdge (graph , 6 , 8 );
7978
8079 // Centers are 2
81- System .out .println (findTreeCenters (graph ) + " \n " );
80+ System .out .println (findTreeCenters (graph ));
8281
8382 // Centers are 0
8483 List <List <Integer >> graph2 = createEmptyTree (1 );
85- System .out .println (findTreeCenters (graph2 ) + " \n " );
84+ System .out .println (findTreeCenters (graph2 ));
8685
8786 // Centers are 0,1
8887 List <List <Integer >> graph3 = createEmptyTree (2 );
8988 addUndirectedEdge (graph3 , 0 , 1 );
90- System .out .println (findTreeCenters (graph3 ) + " \n " );
89+ System .out .println (findTreeCenters (graph3 ));
9190
9291 // Centers are 1
9392 List <List <Integer >> graph4 = createEmptyTree (3 );
9493 addUndirectedEdge (graph4 , 0 , 1 );
9594 addUndirectedEdge (graph4 , 1 , 2 );
96- System .out .println (findTreeCenters (graph4 ) + " \n " );
95+ System .out .println (findTreeCenters (graph4 ));
9796
9897 // Centers are 1,2
9998 List <List <Integer >> graph5 = createEmptyTree (4 );
10099 addUndirectedEdge (graph5 , 0 , 1 );
101100 addUndirectedEdge (graph5 , 1 , 2 );
102101 addUndirectedEdge (graph5 , 2 , 3 );
103- System .out .println (findTreeCenters (graph5 ) + " \n " );
102+ System .out .println (findTreeCenters (graph5 ));
104103
105104 // Centers are 2,3
106105 List <List <Integer >> graph6 = createEmptyTree (7 );
@@ -110,6 +109,6 @@ public static void main(String[] args) {
110109 addUndirectedEdge (graph6 , 3 , 4 );
111110 addUndirectedEdge (graph6 , 4 , 5 );
112111 addUndirectedEdge (graph6 , 4 , 6 );
113- System .out .println (findTreeCenters (graph6 ) + " \n " );
112+ System .out .println (findTreeCenters (graph6 ));
114113 }
115114}
0 commit comments