public void connect(TreeLinkNode root) {
        
        TreeLinkNode cur = root;

        
        while (cur != null) {
            TreeLinkNode next = null;
            TreeLinkNode prev = null;
            
            while (cur != null) {
                if (next == null) {
                    if (cur.left != null)
                        next = cur.left;
                    else
                        next = cur.right;
                }
                
                if (cur.left != null) {
                    if (prev != null)
                        prev.next = cur.left;
                    prev = cur.left;
                }
                
                if (cur.right != null) {
                    if (prev != null)
                        prev.next = cur.right;
                    prev = cur.right;
                }
                   
                    
                cur = cur.next;
            }
            cur = next;
        }
        


    }