//check the code for the above , run it on ide ,
//and tested it yourself with different test cases.
#include <bits/stdc++.h>
using namespace std;
struct treenode{
int data;
treenode *left;
treenode *right;
};
treenode* create(int data){
treenode *temp = (treenode*)malloc(sizeof(treenode));
temp->data = data;
temp->left = temp->right = NULL;
return temp;
}
int solve(treenode *root) { // will return 0 always
int x;
if(root == NULL) return 0;
else
if(root->data % 2 == 1){ // changing odd data items
root->data -= 1;
x++;
}
return solve(root->left) + solve(root->right);
}
void inorder(treenode *root) {
if(root == NULL) return;
inorder(root->left);
cout << root->data <<" ";
inorder(root->right);
}
int main(){
treenode *root;
root = create(4);
root->left = create(1);
root->right = create(7);
root->left->left = create(6);
root->left->right = create(4);
root->right->left = create(2);
root->left->left->right = create(8);
root->left->right->left = create(2);
root->right->left->left = create(8);
cout << solve(root) << endl;
inorder(root);
cout << endl;
return 0;
}

// output
0
6 8 0 2 4 4 8 2 6