Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- typedef struct Node *po;
- int A[] = { 3, -2, 11, 7, 12, 1, 4, 5, 33, 13 };
- int elBroi = 10;
- int B[10];
- int i = 0;
- int jm = 0;
- po ibd(int n);
- void printTriTo(po help);
- struct Node {//всеки елемент на дървото
- int Data;
- po Left;
- po Right;
- };
- int main() {
- //броят на данните е известен
- cout << "Im doing stuff" << endl;
- po root;
- root = ibd(elBroi);
- cout << "Stuff has been done" << endl;
- cout << "Im pritining stuff" << endl;
- printTriTo(root);
- return 0;
- }
- po ibd(int n) {
- po pesho;
- pesho = new Node;//нов елемент
- if (n > 0) {
- pesho = new Node;
- pesho->Data = A[i];
- i++;
- pesho->Left = ibd(n / 2);//ляво
- pesho->Right = ibd(n - n / 2 - 1);//дясно
- return pesho;
- }
- else return NULL;//върни укакзател към нищото, листо
- //алгоритъмът слага данни на потъване, но закача структурата на изплуване
- }
- void printTriTo(po help) {
- if (help == NULL) return;
- //закачи ибд от ляво
- printTriTo(help->Left);
- //операция над корен
- cout << help->Data << endl;
- B[jm] = help->Data;
- jm++;
- //закачи ибд от дясно
- printTriTo(help->Right);
- }
Advertisement
Add Comment
Please, Sign In to add comment