fork download
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<stdbool.h>
  4. #include<limits.h>
  5.  
  6. struct tree
  7. {
  8. int data;
  9. struct tree* left;
  10. struct tree* right;
  11. };
  12. typedef struct tree tree;
  13.  
  14. tree* create(int data)
  15. {
  16. tree* temp=(tree*)malloc(sizeof(tree));
  17. temp->data=data;
  18. temp->left=NULL;
  19. temp->right=NULL;
  20. return temp;
  21. }
  22.  
  23. tree* insertion(tree* root,int data)
  24. {
  25. if(root==NULL)
  26. {
  27. root=create(data);
  28. return root;
  29. }
  30. else
  31. {
  32. if(root-> data > data)
  33. {
  34. root->left=insertion(root->left,data);
  35. }
  36. else
  37. {
  38. root->right=insertion(root->right,data);
  39. }
  40. return root;
  41. }
  42. }
  43.  
  44. tree* preorder(tree* root)
  45. {
  46. if(root==NULL)
  47. {
  48. return NULL;
  49. }
  50. printf(" %d ",root->data);
  51. preorder(root->left);
  52. preorder(root->right);
  53. }
  54.  
  55. void Print_node(tree* root, int space)
  56. {
  57. if (root == NULL)
  58. return;
  59.  
  60. space += 5;
  61.  
  62. Print_node(root->right, space);
  63.  
  64. printf("\n");
  65. for (int i = 5; i < space; i++)
  66. printf(" ");
  67. printf("%d\n", root->data);
  68.  
  69. Print_node(root->left, space);
  70. }
  71.  
  72. int Totalsum(tree* root)
  73. {
  74. if(root==NULL)
  75. {
  76. return 0;
  77. }
  78. return root->data+Totalsum(root->left)+Totalsum(root->right);
  79. }
  80.  
  81. int countnode(tree* root)
  82. {
  83. if(root==NULL)
  84. {
  85. return 0;
  86. }
  87. return 1+countnode(root->left)+countnode(root->right);
  88. }
  89.  
  90. int internalnodes(tree* root)
  91. {
  92. if(root==NULL)
  93. {
  94. return 0;
  95. }
  96. else
  97. {
  98. if(root->left==NULL && root->right==NULL)
  99. {
  100. return 0;
  101. }
  102. return root->data+internalnodes(root->left)+internalnodes(root->right);
  103. }
  104. }
  105.  
  106. int leafsum(tree* root)
  107. {
  108. if(root==NULL)
  109. {
  110. return 0;
  111. }
  112. int sum=0;
  113. if(root->left==NULL && root->right==NULL)
  114. {
  115. sum=sum+root->data;
  116. }
  117. sum=sum+leafsum(root->left);
  118. sum=sum+leafsum(root->right);
  119.  
  120. return sum;
  121. }
  122.  
  123. int Evensum(tree* root)
  124. {
  125. if(root==NULL)
  126. {
  127. return 0;
  128. }
  129. int sum=0;
  130. if((root->data)%2==0)
  131. {
  132. sum=sum+root->data;
  133. }
  134. sum=sum+Evensum(root->left);
  135. sum=sum+Evensum(root->right);
  136. return sum;
  137. }
  138.  
  139. int oddsum(tree* root)
  140. {
  141. if(root==NULL)
  142. {
  143. return 0;
  144. }
  145. int sum=0;
  146. if((root->data)%2!=0)
  147. {
  148. sum=sum+root->data;
  149. }
  150. sum=sum+oddsum(root->left);
  151. sum=sum+oddsum(root->right);
  152. return sum;
  153. }
  154.  
  155. int findmaxvalue(tree* root)
  156. {
  157. if(root==NULL)
  158. {
  159. return 0;
  160. }
  161. int left=findmaxvalue(root->left);
  162. int right=findmaxvalue(root->right);
  163. int maximum=root->data;
  164. if(left> maximum)
  165. {
  166. maximum=left;
  167. }
  168. if(right>maximum)
  169. {
  170. maximum=right;
  171. }
  172.  
  173. return maximum;
  174. }
  175.  
  176. int findminivalue(tree* root)
  177. {
  178. if(root==NULL)
  179. {
  180. return INT_MAX;
  181. }
  182. int left=findminivalue(root->left);
  183. int right=findminivalue(root->right);
  184. int minimum=
  185.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int findminivalue(tree*)’:
prog.cpp:184:16: error: expected primary-expression at end of input
     int minimum=
                ^
prog.cpp:184:16: error: expected ‘}’ at end of input
prog.cpp:177:1: note: to match this ‘{’
 {
 ^
prog.cpp: In function ‘tree* preorder(tree*)’:
prog.cpp:52:13: warning: control reaches end of non-void function [-Wreturn-type]
     preorder(root->right);
     ~~~~~~~~^~~~~~~~~~~~~
prog.cpp: In function ‘int findminivalue(tree*)’:
prog.cpp:183:29: warning: control reaches end of non-void function [-Wreturn-type]
     int  right=findminivalue(root->right);
                ~~~~~~~~~~~~~^~~~~~~~~~~~~
stdout
Standard output is empty