1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | struct Node{ int value; Node* next; }; int average(Node* p){ int sum = 0; int n = 0; if(p == nullptr) //nullptr => NULL (nullptr == c++11) return 0; while(p != nullptr){ //nullptr => NULL (nullptr == c++11) sum += p->value; p = p->next; ++n; } return (sum/n); } |