c语言指针链表
来源:互联网 发布:算法还是编码 编辑:程序博客网 时间:2024/06/03 14:09
#include<stdio.h>#include<stdlib.h>struct NODE{int num;char name[20];char sex;float score;struct NODE *next;};struct NODE *creat(){int n;struct NODE *head, *pf, *pb;int i;printf("how many student:");scanf("%d", &n);for (i = 0; i < n; i++){pb = (struct NODE*)malloc(sizeof(struct NODE));printf("input the %d student:\n", i + 1);scanf("%d", &(pb->num));scanf("%s", (pb->name));scanf("%c");scanf("%c", &(pb->sex));scanf("%f", &(pb->score));if (i == 0) pf = head = pb;else pf->next = pb;pb->next = NULL;pf = pb;}return(head);}struct NODE *findmax(struct NODE *n){if (NULL == n){printf("错误:链表为空\n");exit(-1);}struct NODE *head;struct NODE *max;max = n;head = n;while (1){if (head->score > max->score)max = head;head = head->next;if (head == NULL)break;}return(max);}void prn(struct NODE *p){printf("the max is:\n%d %s %c %g", p->num, p->name, p->sex, p->score);}void clear(struct NODE *head){NODE *next; if (head == NULL){printf("clearList函数执行,链表为空\n");return;}while (head->next != NULL){next = head->next;free(head);head = next;}}int main(){NODE *p, *head;head = creat();//创建链表p = findmax(head);//查找成绩最好的学生prn(p); //打印信息clear(head);//释放空间}
1 0
- c语言指针链表
- C语言指针-链表逆转
- C语言指针函数链表复习
- c语言链表 头指针
- C语言指针和链表操作
- C语言 头指针链表
- 由链表初始化看C语言的二级指针
- c语言链表 关于指针参数调用问题
- 由链表初始化看C语言的二级指针
- 由链表初始化看C语言的二级指针
- C语言中的二级指针(2) -- 链表操作
- c语言-指针实现链表增删改查
- 链表初始化看C语言的二级指针(转)
- 程序设计C语言-静态链表及指针
- 学习C语言指针和链表的体会
- c语言练习题——指针和链表训练
- C语言指针、链表与文件操作详解
- C语言中的指针
- 自己写控制浮点数显示位数
- Mysql注入之一 联合注入
- Linux service network restart重启网络失败
- c++中的vector
- 完美处理SpringMVC文件上传的一系列问题(无法获取参数、断点、分片等)
- c语言指针链表
- POJ 3517 And Then There Was One 可能会
- VS2010鼠标变为灰色块的解决方案
- 倒计时有三种写法
- JDBC与JSP初识
- Leetcode-415. Add Strings
- Android原生与H5交互的实现
- 悟道
- 北漂的程序猿何去何从