JavaLab2/src/lab2/model/DisjointSet.java
public void union(Integer x, Integer y){
        Integer xRoot = find(x);//O(log n)
        Integer yRoot = find(y);//O(log n)

        if(xRoot == yRoot)
            return;

        if(ranks.get(xRoot) < ranks.get(yRoot)){
            Integer tmp = xRoot;
            xRoot = yRoot;
            yRoot = tmp;
        }

        parents.set(yRoot, xRoot);
        if(ranks.get(xRoot) == ranks.get(yRoot))
            ranks.set(xRoot, xRoot + 1);
    }
//Joins subsets of x-element and y-element. O(log n)
Joins subsets of x-element and y-element.
Joins subsets of x - element and y - element .
public void union(Integer x, Integer y){
        Integer xRoot = find(x);
        Integer yRoot = find(y);
        if(xRoot == yRoot)
            return;
        if(ranks.get(xRoot) < ranks.get(yRoot)){
            Integer tmp = xRoot;
            xRoot = yRoot;
            yRoot = tmp;
        }
        parents.set(yRoot, xRoot);
        if(ranks.get(xRoot) == ranks.get(yRoot))
            ranks.set(xRoot, xRoot + 1);
    }
public void union ( Integer x , Integer y ) { Integer xRoot = find ( x ) ; Integer yRoot = find ( y ) ; if ( xRoot == yRoot ) return ; if ( ranks . get ( xRoot ) < ranks . get ( yRoot ) ) { Integer tmp = xRoot ; xRoot = yRoot ; yRoot = tmp ; } parents . set ( yRoot , xRoot ) ; if ( ranks . get ( xRoot ) == ranks . get ( yRoot ) ) ranks . set ( xRoot , xRoot + 1 ) ; }
Joins subsets of x-element and y-element.
Joins subsets of x - element and y - element .
//O(log n) //O(log n)