Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct Tree
- {
- int data;
- Tree* left;
- Tree* right;
- };
- Tree* dobavi(int data) {
- Tree* node = new Tree;
- node->data = data;
- node->left = NULL;
- node->right = NULL;
- return(node);
- }
- void ogledalno(Tree* node)
- {
- if (node == nullptr)
- return;
- else {
- Tree* temp;
- ogledalno(node->left);
- ogledalno(node->right);
- temp = node->left;
- node->left = node->right;
- node->right = temp;
- }
- }
- void podredi(Tree* node)
- {
- if (node == nullptr)
- return;
- podredi(node->left);
- cout << node->data << " ";
- podredi(node->right);
- }
- int main()
- {
- Tree *root = dobavi(1);
- root->left = dobavi(2);
- root->right = dobavi(3);
- root->left->left = dobavi(4);
- root->left->right = dobavi(5);
- cout << "Dvoichno durvo: \n";
- podredi(root);
- ogledalno(root);
- cout << "\nOgledalnoto durvo: \n";
- podredi(root);
- cout << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement