wintest

СЛАВОВА НОУД

Dec 4th, 2017
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.01 KB | None | 0 0
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. typedef struct Node *po;
  5.  
  6. po ibd(int n);
  7. void printTriTo(po help);
  8. struct Node {//всеки елемент на дървото
  9.     int Data;
  10.     po Left;
  11.     po Right;
  12. };
  13.  
  14. int main() {
  15.     //на полето дата сложи число въведено
  16.     int n;
  17.     cin >> n;
  18.  
  19.     //div pesho ;)
  20.  
  21.     //броят на данните е известен
  22.     cout << "Im doing stuff" << endl;
  23.     po root;
  24.     root = ibd(n);
  25.  
  26.     cout << "Im pritining stuff" << endl;
  27.     printTriTo(root);
  28.     return 0;
  29.  
  30. }
  31. po ibd(int n) {
  32.     po pesho;
  33.     pesho = new Node;//нов елемент
  34.     int x;
  35.     if (n > 0) {
  36.         pesho = new Node;
  37.         cin >> x;
  38.         pesho->Data = x;
  39.         pesho->Left = ibd(n/2);//ляво
  40.         pesho->Right = ibd(n - n/2 - 1);//дясно
  41.         return pesho;
  42.     }
  43.     else return NULL;//върни укакзател към нищото, листо
  44. }
  45. void printTriTo(po help) {
  46.     if (help == NULL) return;
  47.  
  48.  
  49.     printTriTo(help->Left);
  50.     cout << help->Data << endl;
  51.     printTriTo(help->Right);
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment