动态单向链表的建立、输出、删除、插入
- 动态链表的建立
建立链表的函数返回<头指针>;
malloc函数(返回void地址)不断分配新的空间给新建的结点;
链表的特征就是结点中包含下一结点的位置信息;
#include <stdio.h>
#include <stdlib.h>
#define LEN sizeof(struct Student)
struct Student
{
int num;
int score;
struct Student* next;
};
int n;//记录节点数
struct Student* creat(void)//函数建立链表,返回头指针
{
struct Student* p1,* p2,* head;
n = 0;
p1 =p2= (struct Student*)malloc(LEN);
printf("input information:\n");
head = NULL;
scanf_s("%d%d", &p1->num, &p1->score);
while (p1->num != 0)//以0为输入终止标志
{
n++;
if (n == 1) head