既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上C C++开发知识点,真正体系化!
由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新
前提:链表(头指针)
后续:无
返回:无
{
walker <- list
while (walker != null)
{
print (*walker).data
walker <- (*walker).link
}
}
## 4 代码示例
根据上述内容,可以编写创建单向动态链表及输出单向链表内容的代码示例。
代码示例内容如下:
#include <stdio.h>
#include <malloc.h>
#define STRUCT_LEN sizeof(struct student)
struct student
{
int stu_num; /* student number /
float stu_score; / student score /
struct student next;
};
int main()
{
/* declaration of func /
struct student create(void);
void print(struct student * list);
struct student* list;
list = create();
print(list);
return 0;
}
/*
-
this is the create linked list function.
-
when student number is 0, create operation finish.
/
struct student create(void)
{
struct student* head; /* head pointer name(the name of linked list) /
struct student tail; /* tail node /
struct student new; /* new node /
int node_num = 0; / node numbers of linked list */
head = NULL;/* allocate a new code space /
tail = new = (struct student)malloc(STRUCT_LEN);
printf(“please input student number and score(delimited by SPACE): \n”);
scanf(“%d %f”, &(*new).stu_num, &(*new).stu_score);while ((new != NULL) && ((new).stu_num != 0))
{
/ node number add one */
node_num = node_num + 1;/* first node */ if (1 == node_num) { head = new; } else { /* let tail point new node, link tail and new */ (*tail).next = new; /* move location of tail to new node */ tail = new; } new = (struct student*)malloc(STRUCT_LEN); scanf("%d %f", &(*new).stu_num, &(*new).stu_score);
}
(*tail).next = NULL;
return head;
}
/*
-
this is the print linked list content function.
*/
void print(struct student * list)
{
struct student *walker;
walker = list;printf(“The linked list contents(student number and score) as followed:\n”);
printf(“[student number] [student score]\n”);while (walker != NULL)
{
printf(“%d %-f\n”, (*walker).stu_num, (*walker).stu_score);
walker = (*walker).next;
}return;
}
上述代码的编译及运行结果如下:

说明:


**既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上C C++开发知识点,真正体系化!**
**由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新**
**[如果你需要这些资料,可以戳这里获取](https://bbs.csdn.net/topics/618668825)**
!**
**由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新**
**[如果你需要这些资料,可以戳这里获取](https://bbs.csdn.net/topics/618668825)**