中缀,前缀或后缀顺序通过BST得到降序打印元素
Infix, prefix or postfix order trough BST to get descending order of printed elements
我知道如果我们以中缀顺序打印BST,我将得到树中包含的元素的升序。如何得到降序?使用后缀还是前缀?
后缀和前缀都不会给出降序。您需要再次使用中缀,但是首先从右子节点下降(当正常遍历首先从左节点下降时)。
p = root;
push(p);
p = p->rightchild;
while(stack is not empty) {
while(p != NULL) {
push(p);
p = p->rightchild;
}
p = pop();
print p->data;
if(p->leftchild != NULL) {
p = p->leftchild;
}
}
相关文章:
- 为什么我的递归函数按降序打印,然后按升序打印?
- 我正在尝试按降序对地图进行排序,但没有得到预期的结果?
- 如何在 c++ 中根据第二个元素按降序对列表进行排序
- 如何按矩阵行的总和降序对矩阵进行排序 C++.
- priority_queue使用降序向量实现最小堆的语法差异
- 插入按降序排序
- 如何使用cpp编写选择排序算法以降序对元素列表进行排序?
- 我怎么不能按课程代码的降序对数字进行排序
- 如何使用布尔函数按降序对数组进行排序?
- 如何按降序排序?
- 程序,它接受用户输入的字符并按出现的降序显示它们
- 数组将排序排序为降序而不是升序
- 如何按降序对标准数组进行排序 - C++ 11.
- 如何按降序打印数组?
- 按降序C 排序矢量
- 使用相同的 for 循环按升序或降序遍历地图
- 使用QuickSort算法以降序排序向量
- 偶数升序排序,奇数降序排序
- 按降序C++写入 4 个变量的有效方法
- 中缀,前缀或后缀顺序通过BST得到降序打印元素