Question
Solution Preview
This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.
#include <iostream>#include <fstream>
using namespace std;
#define MAX_CHILD 2
#define MAX_NODES 100
struct NODE{
int child[MAX_CHILD];
int count_child;
};
// function to recursively do a Depth first search traversing
int DFS(NODE** node, int index)
{
int count = 1; // every node is in its weight
// Sum weights of child nodes
for (int i = 0; i < node[index]->count_child; i++)
{
count += DFS(node, node[index]->child[i]);
}
return count;
}...