static inline uint64_t count_helper(struct node *curr) { if (curr == NULL) return 0ULL; return 1ULL + count_helper(curr->children[0]) + count_helper(curr->children[1]); }
/* preorder DFS */ static void count_helper(node *n, l_int32 *pcount) { if (n) (*pcount)++; else return; count_helper(n->left, pcount); count_helper(n->right, pcount); }
int count_helper(int arr[], int i, int n) { if (n == 0) return 1; if (i < 0 || n < 0) { return 0; } // either choose current coin or not return count_helper(arr, i, n - arr[i]) + count_helper(arr, i-1, n); }
/* * l_rbtreeGetCount() * * Input: t (rbtree) * Return: count (the number of nodes in the tree); 0 on error */ l_int32 l_rbtreeGetCount(L_RBTREE *t) { l_int32 count = 0; node *n; if (!t) return 0; n = t->root; count_helper(n, &count); return count; }
uint64_t count_nodes(struct gentrie *trie) { struct node *rnode = trie->root; return count_helper(rnode); }
int count1(int arr[], int size, int n) { return count_helper(arr, size-1, n); }