```
public void connect(TreeLinkNode head) {
while(head != null){
TreeLinkNode nextHead = head.left;
for(TreeLinkNode node = head; node!=null; node = node.next){
if(node.left!=null) node.left.next = node.right;
if(node.right!=null && node.next!=null) node.right.next = node.next.left;
}
head = nextHead;
}
}
```