Advertisement
_Kripaka001_

treeRecursion 3

Aug 8th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. char vivesti(int arrayInt, char symbol, int i){
  6.     while(i < arrayInt){
  7.         cout << symbol << vivesti(arrayInt, symbol, i+1);
  8.         cout << "1";
  9.     }
  10. }
  11.  
  12. void buildBody(int x, char symbol, int i){
  13.     vivesti(x, symbol, i);
  14.     cout << "4";
  15.     cout << "*";
  16. }
  17. char buildTree(int userNumber, int i, char symbol){
  18.     if(i >= userNumber){
  19.         i = 0;
  20.         symbol = ' ';
  21.         buildBody(userNumber, symbol, i);
  22.     }else{
  23.         if(i < userNumber*2){
  24.  
  25.             symbol = ' ';
  26.             int x = userNumber - (i/2);
  27.             cout << "0";
  28.             vivesti(x, symbol, i);
  29.  
  30.             symbol = '*';
  31.             x = i+1;
  32.             vivesti(x, symbol, i);
  33.             cout << "2";
  34.  
  35.             cout << endl;
  36.             cout << "3";
  37.             return buildTree(userNumber, i+2, symbol);
  38.         }
  39.     }
  40.  
  41. }
  42.  
  43. int main()
  44. {
  45.     int userNumber,i = 0;
  46.     char symbol;
  47.     cout << " Enter number to build a tree - ";
  48.     cin >> userNumber;
  49.     cout << endl;
  50.  
  51.     buildTree(userNumber, i, symbol);
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement