当前位置:   article > 正文

二叉树的生成,几种遍历,销毁的c++实现_c++销毁二叉树

c++销毁二叉树
  1. #include<iostream>
  2. #include<stdio.h>
  3. #include<vector>
  4. #include<map>
  5. #include<algorithm>
  6. #include<queue>
  7. using namespace std;
  8. struct TreeNode {
  9. char val;
  10. struct TreeNode *left;
  11. struct TreeNode *right;
  12. TreeNode(char x) :
  13. val(x), left(NULL), right(NULL) {
  14. }
  15. };
  16. TreeNode* make_tree(){
  17. TreeNode* A = new TreeNode('A'); TreeNode* B = new TreeNode('B');
  18. TreeNode* C = new TreeNode('C'); TreeNode* D = new TreeNode('D');
  19. TreeNode* E = new TreeNode('E'); TreeNode* F = new TreeNode('F');
  20. TreeNode* G = new TreeNode('G'); TreeNode* H = new TreeNode('H');
  21. TreeNode* K = new TreeNode('K');
  22. A->left = B;
  23. A->right = E;
  24. B->right = C;
  25. C->left = D;
  26. E->right = F;
  27. F->left = G;
  28. G->left = H;
  29. G->right = K;
  30. return A;
  31. }
  32. void delet_tree(TreeNode* head){
  33. if (head ==
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/622020
推荐阅读
相关标签
  

闽ICP备14008679号