题目描述:
解题思路:
代码实现:
代码语言:javascript
复制#include <iostream>
#include <algorithm>
using namespace std;
struct Lnode {
int data;
Lnode* next;
Lnode() {}
Lnode(int data, Lnode* next) : data(data), next(next) {}
};
int caortx(Lnode* HL, int x) {
Lnode* p = HL;
int cnt = 0;
while (p) {
if (p->data == x) {
cnt ;
}
p = p->next;
}
return cnt;
}
int main() {
Lnode a, b, c, d, e;
a.next = &b;
b.next = &c;
c.next = &d;
d.next = &e;
e.next = NULL;
a.data = 1;
b.data = 2;
c.data = 1;
d.data = 4;
e.data = 1;
cout << caortx(&a, 1);
return 0;
}