首页 新闻 会员 周边 捐助

新手上路C++求解

0
[已关闭问题] 关闭于 2017-05-16 09:12

#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为什么是空指针?

哪错了?

奋斗xian的主页 奋斗xian | 菜鸟二级 | 园豆:202
提问于:2017-05-15 22:28
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册