广州网站建设在线,河北建设工程信息网官,俱乐部网站方案,单页静态网站怎么做给定一个n节点的二叉树#xff0c;写出一个O(n)时间递归过程#xff0c;将该树每个节点关键字输出
#xff08;算法导论第十章10.4-2#xff09;
#include iostream
templatetypename T
void TraverseBinaryTreeIndex(const BinaryTreeNodeIndexT写出一个O(n)时间递归过程将该树每个节点关键字输出
算法导论第十章10.4-2
#include iostream
templatetypename T
void TraverseBinaryTreeIndex(const BinaryTreeNodeIndexT* array,const BinaryTreeNodeIndexT root)
{std::coutroot.key ;if(root.left!-1){TraverseBinaryTreeIndex(array,array[root.left]);}if(root.right!-1){TraverseBinaryTreeIndex(array,array[root.right]);}
}辅助类 1⃣️BinaryTreeNodeIndex 地址链接 测试代码 BinaryTreeNodeIndexint binaryTreeNode[10] {BinaryTreeNodeIndexint(12,5,6,2),BinaryTreeNodeIndexint(15,7,7,-1),BinaryTreeNodeIndexint(4,0,9,-1),BinaryTreeNodeIndexint(10,5,4,8),BinaryTreeNodeIndexint(2,3,-1,-1),BinaryTreeNodeIndexint(18,-1,0,3),BinaryTreeNodeIndexint(7,0,-1,-1),BinaryTreeNodeIndexint(14,1,5,1),BinaryTreeNodeIndexint(21,3,-1,-1),BinaryTreeNodeIndexint(5,2,-1,-1),};TraverseBinaryTreeIndex(binaryTreeNode,binaryTreeNode[5]);coutendl;