给定一个单链表,其数据元素为正整数,要求实现一个函数,可输出该表中偶数结点的个数,若表空,输出0。 输入样例: 5 1 2 3 4 5 输出样例: 2 #includeusing namespace std; #define OK 1 #define ERROR 0 #define OVERFLOW -2 #define MAXSIZE 100 typedef int Status; typedef int ElemType; typedef struct LNode { ElemType data; struct LNode *next; }LNode, *LinkList; Status InitList(LinkList &L) { L = new LNode; L->next = NULL; return OK; } void CreateList(LinkList L, int n) { LNode *p, *r; int i; r = L; for(i = 0; i < n; ++i) { p = new LNode; cin >> p->data; r->next = p; r = p; } r->next = NULL; } int CountEven(LinkList L) { int j = 0; LNode *p = L->next; while (p) { if (p->data % 2 == 0) j++; p = p->next; } return j; } int main() { LinkList La = NULL; int n; InitList(La); cin >> n; CreateList(La, n); cout << CountEven(La); return 0; }



