#include<iostream>
using namespace std;
struct student {
int xuehao;
int cj;
char name[20];
};
struct jiedian {
student date;
jiedian *next;
};
void lianbiao(jiedian *L, int n, void(*input) (student *S));
void input(student *S);
void shanchu(jiedian *P);
void printf(student *N1);
void listlianbiao(jiedian *N, void(*printf)(student *N1));
int main() {
int n;
cout << "学生个数:\n";
cin >> n;
jiedian L;
L.next = 0;
lianbiao(&L, n, input);
listlianbiao(&L, printf);
shanchu(&L);
}
void lianbiao(jiedian *L, int n,void(*input) (student *S)){
L = new jiedian;
for (; n > 0; n--) {
jiedian *s;
s = new jiedian;
input(&(s->date));
s->next = L->next;
L->next = s;
}
}
void input(student *S) {
cout << "输入学生的学号:\n";
cin >> S->xuehao;
cout << "学生的姓名:\n";
cin >> S->name;
cout << "学生成绩:\n";
cin >> S->cj;
}
void shanchu(jiedian *P) {
jiedian *Q, *W = P;
while (W==NULL) {
Q = W->next;
delete W;
W = Q;
}
delete P;
}
void printf(student *N1){
cout << "输入学生的学号:" << N1->xuehao;
cout << "学生的姓名:" << N1->name;
cout << "学生成绩:"<<N1->cj;
}
void listlianbiao(jiedian *N, void(*printf)(student *N1)) {
jiedian *P1;
P1 = N->next;
while (P1 == NULL) {
printf(&(P1->date));
P1 = P1->next;
}
}
这里的*N为什么是空指针?
哪错了?