Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- #include <iostream>
- using namespace std;
- struct tree {
- int data;
- tree *left,*right;
- };
- tree *root;
- void add(int x, tree *&root)
- {
- if (!root)
- {
- root = new tree;
- root->data = x;
- root->left = root->right = NULL;
- }
- else if (x < root->data)
- add(x, root->left);
- else if (x > root->data)
- add(x, root->right);
- }
- void stepen(int x, tree *root)
- {
- //тут нужно описать функцию
- }
- void deletet(tree *&root)
- {
- if (root)
- {
- delete(root->left);
- delete(root->right);
- delete root;
- root = NULL;
- }
- }
- void print(tree *root)
- {
- if (root)
- {
- if (root->left == NULL && root->right == NULL) cout << root->data << ' ';
- else
- {
- print(root->left); print(root->right);
- }
- }
- }
- int main() {
- ifstream in("input.txt");
- int x;
- while (in.peek() != EOF) {
- in >> x;
- add(x, root);
- }
- print(root); cout << endl;
- stepen(6, root); cout << endl;
- deletet(root);
- in.close();
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement