编辑代码

#include <iostream>
using namespace std;

struct Student{
    int num;
    float score;
    Student *next;
};

int main() {
    //使用结构体实现链表
    Student a, b, c, *head, *p;
    void student(Student *pstu,int num, float score);
    void student_to_String(Student *pstu);

    // student(&a, 1001, 82.5);
    // student(&b, 1002, 88.1);
    // student(&c, 1003, 90.0);

    head = &a;
    a.next = &b;
    b.next = &c;
    c.next = NULL;

    p = head;

    int i = 0, j = 3;

    do{
        student(p,1001 + i, 80.0 + j * i);
        p = (*p).next;
        i ++;
    }while(p != NULL);

    p = head;

    do{
        student_to_String(p);
        p = (*p).next;
    }while(p != NULL);

	return 0;
}

void student(Student *pstu, int num, float score){
    Student *stu;
    stu = pstu;
    (*stu).num = num;
    (*stu).score = score;
    printf("学生节点构造完毕!\n");
}

void student_to_String(Student *pstu){
    Student *stu;
    stu = pstu;
    printf("---------*****---------\n");
    printf("该节点的信息如下:\n");
    printf("该同学的学号为:%d\n", (*stu).num);
    printf("该同学的分数为:%3.2f\n", (*stu).score);
    printf("该节点信息输出完毕!\n");
}