fork download
  1.  
  2. #include <bits/stdc++.h>
  3.  
  4. using namespace std;
  5.  
  6. struct node {
  7. node * left;
  8. node * right;
  9. int val;
  10. };
  11.  
  12. int main() {
  13. node * tmp = new node();
  14. node * tmp2 = new node();
  15. node * tmp3 = new node();
  16. node * tmp4 = new node();
  17. node * tmp5 = new node();
  18. node * tmp6 = new node();
  19. node * tmp7 = new node();
  20. node * tmp8 = new node();
  21.  
  22. tmp->val = 50;
  23. tmp2->val = 20;
  24. tmp3->val = 18;
  25. tmp4->val = 34;
  26. tmp5->val = 17;
  27. tmp6->val = 19;
  28. tmp7->val = 30;
  29. tmp8->val = 35;
  30.  
  31. tmp->left = tmp2;
  32.  
  33. tmp2->left = tmp3;
  34. tmp2->right = tmp4;
  35.  
  36. tmp3->left = tmp5;
  37. tmp3->right = tmp6;
  38.  
  39. tmp4->left = tmp7;
  40. tmp4->right = tmp8;
  41.  
  42. int Count = 0;
  43.  
  44. node * root = tmp;
  45.  
  46. while(root->val!=30){
  47. if(root->val<30){
  48. root=root->right;
  49. }
  50. while(root->val>=30){
  51. root=root->left;
  52. if(root->val >30 and root->val <=70){
  53. root=root->left;
  54. Count++;
  55. }
  56. }
  57. }
  58.  
  59. cout << Count << endl;
  60. return 0;
  61. }
Runtime error #stdin #stdout 0s 4548KB
stdin
Standard input is empty
stdout
Standard output is empty