Advertisement
Guest User

Untitled

a guest
May 30th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. #include <fstream>
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. struct tree {
  7. int data;
  8. tree *left,*right;
  9. };
  10. tree *root;
  11.  
  12. void add(int x, tree *&root)
  13. {
  14. if (!root)
  15. {
  16. root = new tree;
  17. root->data = x;
  18. root->left = root->right = NULL;
  19. }
  20. else if (x < root->data)
  21. add(x, root->left);
  22. else if (x > root->data)
  23. add(x, root->right);
  24. }
  25.  
  26. void stepen(int x, tree *root)
  27. {
  28. //тут нужно описать функцию
  29. }
  30.  
  31. void deletet(tree *&root)
  32. {
  33. if (root)
  34. {
  35. delete(root->left);
  36. delete(root->right);
  37. delete root;
  38. root = NULL;
  39. }
  40. }
  41.  
  42. void print(tree *root)
  43. {
  44. if (root)
  45. {
  46. if (root->left == NULL && root->right == NULL) cout << root->data << ' ';
  47. else
  48. {
  49. print(root->left); print(root->right);
  50. }
  51. }
  52. }
  53. int main() {
  54.  
  55. ifstream in("input.txt");
  56.  
  57. int x;
  58. while (in.peek() != EOF) {
  59. in >> x;
  60. add(x, root);
  61. }
  62. print(root); cout << endl;
  63. stepen(6, root); cout << endl;
  64. deletet(root);
  65. in.close();
  66. system("pause");
  67. return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement