public void merge(LeftistTreeNode root, LeftistTreeNode newNode) {
        // Considering the tree.element with largest value on the top

        if (root.parent == null && root.value.compareTo(newNode.value) < 0) { // invert here to change to small priority on top
            if (newNode.right == null) {
                newNode.right = root;
            } else {
                merge(newNode, root);
            }

            root.parent = newNode;
            newNode.parent = null;
            performSwap(newNode);
            this.root = newNode;
        } else if (root.right == null) {
            root.right = newNode;
            newNode.parent = root;
            performSwap(root);
        } else if (root.right.value.compareTo(newNode.value) < 0) { // invert here to change to small priority on top
            LeftistTreeNode detached = root.right;
            root.right = newNode;
            newNode.parent = root;
            merge(newNode, detached);
            performSwap(newNode);
        } else {
            merge(root.right, newNode);
            performSwap(root.right);
        }
    }