wintest

name your stuff like a decent human being for god's sake

Dec 18th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using std::endl;
  4. using std::cout;
  5. using std::cin;
  6.  
  7. int counter;
  8. int* arr;
  9. int n;
  10.  
  11. typedef struct Node *po;
  12.  
  13. struct Node
  14. {
  15.     int Data;
  16.     po Left;
  17.     po Right;
  18. };
  19.  
  20. po nibd(int left, int right)
  21. {
  22.     po eto;
  23.     if (right - left < 0) return NULL;
  24.     int mid = (left + right) / 2;
  25.     eto = new Node;
  26.     eto->Data = arr[mid];
  27.     eto->Left = nibd(left, mid - 1);
  28.     eto->Right = nibd(mid + 1, right);
  29.     return eto;
  30. }
  31.  
  32. int main()
  33. {
  34.  
  35.     while (cin >> n)
  36.     {
  37.         counter++;
  38.         arr = new int[n];
  39.  
  40.         // Обход на дървото
  41.         for (int i = 0; i < n; i++)
  42.         {
  43.             arr[i] = i;
  44.         }
  45.         // До тук имаме нареден масив
  46.  
  47.         // Рекурсия; от 0 до counter
  48.         nibd(0, n);
  49.     }
  50.  
  51.     return 0;
  52. }
Add Comment
Please, Sign In to add comment