有一資料長這樣[1,2,3,4,5,6]
我用二元樹階層插入是長這樣,可透過比較node大小,來找到最尾端的node做新增
 Dim current As TNode = Root
                Dim parent As TNode = current
                While True
                    parent = current
                    If num < current.data Then
                        current = current.LNode
                        If current Is Nothing Then
                            parent.LNode = newNode
                            Exit While
                        End If
                    Else
                        current = current.RNode
                        If current Is Nothing Then
                            parent.RNode = newNode
                            Exit While
                        End If
                    End If
                End While
結構長這樣
1
2
3
4
5
6
現在我想用階層的方式加入,卻發現沒有一個判斷的方式讓我找到要在哪一個node新增節點
結構要長這樣:
1
/ 
2   3
/ \ /
4  5 6
請問有什麼類似的判斷方式嗎?