(node1: string, node2: string)
| 165 | } |
| 166 | |
| 167 | union(node1: string, node2: string): void { |
| 168 | const root1 = this.find(node1) |
| 169 | const root2 = this.find(node2) |
| 170 | if (root1 !== root2) { |
| 171 | if (this.rank[root1] < this.rank[root2]) { |
| 172 | this.parent[root1] = root2 |
| 173 | } else if (this.rank[root1] > this.rank[root2]) { |
| 174 | this.parent[root2] = root1 |
| 175 | } else { |
| 176 | this.parent[root2] = root1 |
| 177 | this.rank[root1]++ |
| 178 | } |
| 179 | } |
| 180 | } |
| 181 | } |
no test coverage detected