Advertisement
Tolga20

Upr10

Nov 20th, 2019
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.87 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. struct item {
  6.     char info;
  7.     item *L, *R;
  8. };
  9.  
  10. typedef item* point;
  11. point Root;
  12.  
  13. void Create_B_Tree(point &P) { 
  14. char x;
  15.  
  16. cin>>x;
  17. if (x!='0') {
  18.  P=new item; P->info=x; P->L=P->R=NULL;
  19.  cout<<"ляв наследник на "<<P->info<< "= ";
  20.  Create_B_Tree(P->L);
  21.  cout<<"десен наследник на "<<P->info<< "= ";
  22.  Create_B_Tree(P->R);
  23.  }
  24. }
  25.  
  26. void Print1(point P) {
  27.  
  28. if (P) {
  29.    cout << P->info;
  30.    Print1(P->L);
  31.    Print1(P->R);
  32.   }
  33. }
  34.  
  35. void Print2(point P) {
  36.  
  37. if (P) {
  38.    cout << P->info;
  39.    Print2(P->L);
  40.    Print2(P->R);
  41.   }
  42. }
  43.  
  44. void Print3(point P) {
  45.  
  46. if (P) {
  47.    cout << P->info;
  48.    Print3(P->L);
  49.    Print3(P->R);
  50.   }
  51. }
  52.  
  53. /*
  54. void CountP(point P, int &C){
  55.     if (P) {
  56.         C++;
  57.    CountP (P->L, C);
  58.    CountP (P->R, C);
  59.   }
  60.  
  61. }
  62. */
  63.  
  64. /*int CountP(point P){
  65.  
  66.     if (P) return 1 + CountP(P->L) + CountP(P->R);
  67.     else return 0;
  68. }
  69. */
  70.  
  71.  
  72. int CountOP(point P){
  73.  
  74.     if (P) {
  75.    
  76.         if (P->info == '+' || P->info == '-' || P->info == '*' || P->info == '/') {
  77.             return 1 + CountOP(P->L) + CountOP(P->R);
  78.         } else {
  79.             return  CountOP(P->L) + CountOP(P->R);
  80.         }
  81.  
  82.     } else {
  83.         return 0;
  84.     }
  85. }
  86.  
  87. int CountL(point P){
  88.  
  89.     if (P) {
  90.    
  91.         if (CountL(P->L) != 0 || CountL(P->R) != 0) {
  92.             return CountL(P->L) + CountL(P->R);
  93.         } else {
  94.             return 1;
  95.         }
  96.  
  97.     } else {
  98.         return 0;
  99.     }
  100. }
  101.  
  102. int CountD(point P){
  103.  
  104.     if (P) {
  105.    
  106.         if (CountD(P->L) > CountD(P->R)) {
  107.             return 1 + CountD(P->L);
  108.         } else {
  109.             return 1 + CountD(P->R);
  110.         }
  111.        
  112.     } else {
  113.         return 0;
  114.     }
  115. }
  116.  
  117. void main() {
  118.     system("chcp 1251");
  119.     Root=NULL;
  120.     cout<<"корен = ";
  121.     Create_B_Tree(Root);
  122.     //Print1(Root);
  123.     //Print2(Root);
  124.     //Print3(Root);
  125.     //int Lenght=0;
  126.     //CountP(Root, Lenght); cout<< Lenght;
  127.     //cout << CountP(Root);
  128.     //cout << CountOP(Root);
  129.     cout << CountL(Root);
  130.     system("pause");
  131.  
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement