#include <iostream>
using namespace std;
struct node {
int info;
node *next;
};
int Sum_Even_Values(node *head)
{
int sum = 0;
if (head) {
if ((head->info % 2) == 0) {
cout << " + " << head->info;
sum = head->info;
}
sum += Sum_Even_Values(head->next);
}
return sum;
}
int main() {
// ignore that the nodes are on the stack instead of the heap,
// this is just for demonstration purposes, how the nodes are
// allocated is irrelevant...
node nodes[10];
for(int i = 0; i < 10; ++i) {
nodes[i].info = i+1;
nodes[i].next = &nodes[i+1];
}
nodes[9].next = 0;
int sum = Sum_Even_Values(nodes);
cout << " = " << sum;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKc3RydWN0IG5vZGUgewogICAgaW50IGluZm87CiAgICBub2RlICpuZXh0Owp9OwoKaW50IFN1bV9FdmVuX1ZhbHVlcyhub2RlICpoZWFkKQp7CiAgICBpbnQgc3VtID0gMDsKICAgIGlmIChoZWFkKSB7CiAgICAgICAgaWYgKChoZWFkLT5pbmZvICUgMikgPT0gMCkgewogICAgICAgICAgICBjb3V0IDw8ICIgKyAiIDw8IGhlYWQtPmluZm87CiAgICAgICAgICAgIHN1bSA9IGhlYWQtPmluZm87CiAgICAgICAgfQogICAgICAgIHN1bSArPSBTdW1fRXZlbl9WYWx1ZXMoaGVhZC0+bmV4dCk7CiAgICB9CiAgICByZXR1cm4gc3VtOwp9CgppbnQgbWFpbigpIHsKICAgIC8vIGlnbm9yZSB0aGF0IHRoZSBub2RlcyBhcmUgb24gdGhlIHN0YWNrIGluc3RlYWQgb2YgdGhlIGhlYXAsCiAgICAvLyB0aGlzIGlzIGp1c3QgZm9yIGRlbW9uc3RyYXRpb24gcHVycG9zZXMsIGhvdyB0aGUgbm9kZXMgYXJlCiAgICAvLyBhbGxvY2F0ZWQgaXMgaXJyZWxldmFudC4uLgogICAgbm9kZSBub2Rlc1sxMF07CiAgICBmb3IoaW50IGkgPSAwOyBpIDwgMTA7ICsraSkgewogICAgICAgIG5vZGVzW2ldLmluZm8gPSBpKzE7CiAgICAgICAgbm9kZXNbaV0ubmV4dCA9ICZub2Rlc1tpKzFdOwogICAgfQogICAgbm9kZXNbOV0ubmV4dCA9IDA7CgogICAgaW50IHN1bSA9IFN1bV9FdmVuX1ZhbHVlcyhub2Rlcyk7CiAgICBjb3V0IDw8ICIgPSAiIDw8IHN1bTsKICAgIAogICAgcmV0dXJuIDA7Cn0=