【发布时间】:2018-05-19 12:29:48
【问题描述】:
我正在尝试按顺序遍历 AVL 树(从最小值到最大值),并将值保存在数组中。我怎么能做这样的事情?我被困在这个递归中,无法弄清楚如何正确地做到这一点,这是我到目前为止所拥有的:
// Called with node = root node of the AVL tree
// x is the length of the array
// y is 0 at the start
// array is the array I want to fill
void inorder(int* array,Tree_Node* node,int x,int y)
{
if(!node)
{
return;
}
inorder(array, node->getLeft(), x, y);
array[y] = GET_ID(node->getkey());
y++;
if (y == x)
{
return;
}
inorder(array, node->getRight(), x, y);
}
【问题讨论】:
-
您显示的代码有什么问题? “卡住”是什么意思?请read about how to ask good questions,我建议你也阅读this SO question checklist。