链表在C语言中很重要,本文所设计的链表,以一个经典的存储学生学号和成绩的结构体作为例子,具
体的结构体如下:
struct student
{
int num;
float socre;
struct student *next;
};
首先建立一个链表,具体函数如下:
#define <malloc.h> //使用malloc函数需要包含的头文件
#define NULL 0
#define LEN sizeof(struct student)
typedef struct student stu
struct student
{
long num;
float socre;
struct student *next;
}; //
注意不要忘记定义结构体大括号最后要有一个“;”
int n; //n为全局变量,本文件模块中其他函数均可使用它
stu *creat(void)
{
stu *head;
stu *p1,*p2;
n=0;
p1=p2=(struct student *)malloc(LEN);
scanf("%ld,%ld",&p1->num,&p1->socre);
head=NULL;
while(p1->num!=0)
{

这篇博客介绍了如何使用C语言实现链表的反转操作。通过定义指针p、q、temp,并进行一系列的指针操作,实现了链表的就地反转。核心代码在于不断更新指针指向,直至链表末尾。

14万+

被折叠的 条评论
为什么被折叠?



