答案 0 :(得分:4)
您可以首先创建一个节点的2D数组,其中行i
对应于论文中的i
级,而j
列对应于j
个节点在那个级别:
for i = 1 to n:
for j = 1 to i:
A[i][j] = new Node()
然后,节点之间的关系是A[i][j]
节点让孩子为A[i+1][j]
并且正确的孩子为A[i+1][j+1]
。
for i = 1 to n-1:
for j = 1 to i:
A[i][j].left = A[i+1][j]
A[i][j].right = A[i+1][j+1]
for j = 1 to n:
A[n][j].left = null
A[n][j].right = null