Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int COUNT = 0;
- struct Element{
- int data;
- Element* left;
- Element* right;
- };
- Element* ibd(int n){
- Element* d;
- int x;
- int lyavo = n/2;
- int dyasno = n - lyavo - 1;
- if(n>0){
- d = new Element;
- cin >> x;
- d->data = x;
- d->left = ibd(lyavo);
- d->right = ibd(dyasno);
- return d;
- }
- else return NULL;
- }
- void print2(Element* root, int space)
- {
- COUNT = 10;
- if (root == NULL)
- return;
- space += COUNT;
- print2(root->right, space);
- cout << endl;
- for (int i = COUNT; i < space; i++)
- cout << " ";
- cout << root->data << "\n";
- print2(root->left, space);
- }
- int main(){
- int n;
- cin >> n;
- Element* durvo;
- durvo = ibd(n);
- print2(durvo,5);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement