Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- typedef struct Node *po;
- po ibd(int n);
- void printTriTo(po help);
- struct Node {//всеки елемент на дървото
- int Data;
- po Left;
- po Right;
- };
- int main() {
- //на полето дата сложи число въведено
- int n;
- cin >> n;
- //div pesho ;)
- //броят на данните е известен
- cout << "Im doing stuff" << endl;
- po root;
- root = ibd(n);
- cout << "Im pritining stuff" << endl;
- printTriTo(root);
- return 0;
- }
- po ibd(int n) {
- po pesho;
- pesho = new Node;//нов елемент
- int x;
- if (n > 0) {
- pesho = new Node;
- cin >> x;
- pesho->Data = x;
- 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;
- printTriTo(help->Right);
- }
Advertisement
Add Comment
Please, Sign In to add comment