使用链表实现学生信息的存储和管理,可以按照以下步骤进行操作:
typedef struct {
int id;
char name[20];
int age;
} Student;
typedef struct Node {
Student student;
struct Node *next;
} Node;
Node *head = NULL;
Node *tail = NULL;
void addStudent(Student student) {
Node *newNode = (Node *)malloc(sizeof(Node));
newNode->student = student;
newNode->next = NULL;
if (head == NULL) {
head = newNode;
tail = newNode;
} else {
tail->next = newNode;
tail = newNode;
}
}
void printStudents() {
Node *node = head;
while (node != NULL) {
printf("学号:%d, 姓名:%s, 年龄:%d\n", node->student.id, node->student.name, node->student.age);
node = node->next;
}
}
使用以上步骤,可以使用链表来存储和管理学生信息。