[Solved] How to reverse a binary tree [closed]

void reverseLevelOrder(struct node* root) { int h = height(root); int i; for (i=h; i>=1; i–) //THE ONLY LINE DIFFERENT FROM NORMAL LEVEL ORDER printGivenLevel(root, i); } /* Print nodes at a given level */ void printGivenLevel(struct node* root, int level) { if (root == NULL) return; if (level == 1) printf(“%d “, root->data); else if … Read more

[Solved] Counting the number of unival subtrees in a binary tree [closed]

int countUniVals(node* head, bool* unival) { if (!node) { *unival = true; return 0; } bool uniL,uniR; int sum = countUniVals(head->l, &uniL) + countUniVals(head->r, &uniR); if (uniL && uniR && (!head->l || head->l->val == head->val) && (!head->r || head->r->val == head->val)) { sum++; *unival = true; } return sum; } 0 solved Counting the number … Read more

[Solved] Why isn’t std::set just called std::binary_tree? [closed]

Why isn’t std::set just called std::binary_tree? Because Tree doesn’t describe how the interface is used. Set does. std::set does not provide sufficient operations to be used as a general purpose search tree. It only provides an interface to a particular application of a search tree: The representation of a set. Technically the standard doesn’t specify … Read more

[Solved] Function to turn a Binary Tree into the sums of all nodes below each node; segmentation fault if I don’t create a new binary tree [closed]

It is a nuisance when we have to create an MCVE from fragments of a program. However, it’s doable — it’s a pain, but doable. Here’s my variation on your code. Of the 115 lines shown, 35 are what you wrote in the question — roughly. So, I had to create twice as much code … Read more