Advertisement
Guest User

Untitled

a guest
Jun 18th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.02 KB | None | 0 0
  1. void twoDtree::prune(double pct, int tol){
  2.  
  3.     prune(root, pct, tol, root->avg);
  4.  
  5.    
  6. }
  7.  
  8. void twoDtree::prune(Node* node, double pct, int tol, const RGBAPixel& rootAvg) {
  9.     if (node!= NULL) {
  10.         double numThis = (double) numNodesWithinTolerance(node, tol, rootAvg);
  11.         double numLeafNodes = (double) countLeaves(node);
  12.         double totalTolerances = numThis/numLeafNodes;
  13.         numLeafMap->erase(node);
  14.  
  15.         if (totalTolerances >= pct)
  16.             removeSubTrees(node);
  17.  
  18.         else {
  19.             if (node->left != NULL && node->right != NULL) {
  20.                 prune(node->left, pct, tol, node->avg);
  21.                 prune (node->right, pct, tol, node->avg);
  22.             }
  23.         }
  24.     }
  25. }
  26.  
  27.  
  28. int twoDtree::numNodesWithinTolerance(Node* node, int tol, const RGBAPixel& rootAvg) {
  29.     if (node != NULL) {
  30.         if (node->left == NULL && node->right == NULL) {
  31.             if (withinTolerance(node->avg, rootAvg, tol))
  32.                 return 1;
  33.             return 0;
  34.         }
  35.  
  36.         int total = numNodesWithinTolerance(node->left, tol, rootAvg) + numNodesWithinTolerance(node->right, tol, rootAvg);
  37.         return total;
  38.     }
  39.  
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement