Given typedef struct covid *covidDB;
I have two functions here:
unsigned long countResult(covidDB cur) {
unsigned long tmp = 0;
if (isEmpty(cur)) return 0;
tmp += countResult(cur->left);
for (int day = 1; day <= 70; day++) {
if (cur->patients[day] > 0) {
tmp += cur->patients[day];
}
}
return tmp + countResult(cur->right);
}
and
void printDB(covidDB cur) {
if (isEmpty(cur)) return;
printDB(cur->left);
for (int day = 1; day <= 70; day++) {
if (cur->patients[day] > 0)
show
}
printDB(cur->right);
}
Apperently both two functions do inorder traversal through the binary tree. Is it possible to write something like:
void inorder(covidDB cur, /*function*/) {
//do something
}
and in the main function I call
inorder(root, printList);
inorder(root, countList);