#include<iostream>
struct binaryTreeNode {
int data;
struct binaryTreeNode* leftchild;
struct binaryTreeNode* rightchild;
};
void createBinaryTree(struct binaryTreeNode* tree) {
char ch;
std::cin >> ch;
if (ch == -1) {
tree = nullptr;
return;
}
else {
tree = new binaryTreeNode;
tree->data = ch;
createBinaryTree(tree->leftchild);
createBinaryTree(tree->rightchild);
}
}
void showTreeByPreOrder(struct binaryTreeNode* tree) {
if (tree == nullptr) {
return;
}
else {
std::cout << tree->data << std::endl;
showTreeByPreOrder(tree->leftchild);
showTreeByPreOrder(tree->rightchild);
}
}
void showTreeByInOrder(struct binaryTreeNode* tree) {
if (tree == nullptr) {
return;
}
else {
showTreeByInOrder(tree->leftchild);
std::cout << tree->data << std::endl;
showTreeByInOrder(tree->rightchild);
}
}
void showTreeByPosOrder(struct binaryTreeNode* tree) {
if (tree == nullptr) {
return;
}
else {
showTreeByPosOrder(tree->leftchild);
showTreeByPosOrder(tree->rightchild);
std::cout << tree->data << std::endl;
}
}
int main() {
return 0;
}
数据结构与算法-二叉树
于 2022-07-12 22:36:04 首次发布