class Node{
public:
int data;
Node *pLeft = NULL;
Node *pRight = NULL;
};
void qianxubianli(Node *pRoot){
if (pRoot == NULL){return;
}
cout << pRoot->data << " ";
qianxubianli( pRoot->pLeft);
qianxubianli( pRoot->pRight);
}
void zhongxubianli(Node *pRoot){
if (pRoot == NULL){
return;
}
zhongxubianli(pRoot->pLeft);
cout << pRoot->data << " ";
zhongxubianli(pRoot->pRight);
}
void houxubianli(Node *pRoot){
if (pRoot == NULL){
return;
}
houxubianli(pRoot->pLeft);
houxubianli(pRoot->pRight);
cout << pRoot->data << " ";
}
本文介绍了二叉树的三种遍历方式:前序遍历、中序遍历及后序遍历,并提供了详细的C++代码实现。通过这些遍历方法可以有效地处理二叉树数据结构中的各种问题。
47万+

被折叠的 条评论
为什么被折叠?



