65.输出单向链表中节点上最大值
2015-06-25 14:13
453 查看
给定程序是建立一个带头的节点的单项链表,并用随机函数为各节点数据赋值。函数fun的作用是求出单项链表节点(不包括头结点)数据中的最大值,并作为函数值得返回值。
#define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> typedef struct aa { int data; struct aa *next; }NODE; int fun(NODE *h) { int max = -1; NODE *p; p = h->next; while (p) { if (p->data > max) max = p->data; p = p->next; } return max; } outresult(int s, FILE *fp) { fprintf(fp, "The max in link :%d\n", s); } NODE *creatlist(int n, int m) { NODE *h, *p, *s; int i; h = p = (NODE *)malloc(sizeof(NODE)); h->data = 9999; for (i = 1;i <= n;i++) { s = (NODE *)malloc(sizeof(NODE)); s->data = rand() % m; s->next = NULL; p->next = s; p = p->next; } p->next = NULL; return h; } outlink(NODE *h, FILE *fp) { NODE *p; p = h->next; fprintf(fp, "\nThe List:\n\n Head"); while (p) { fprintf(fp, "->%d", p->data); p = p->next; } fprintf(fp, "\n"); } int main() { NODE *head; int m; head = creatlist(12, 100); outlink(head, stdout); m = fun(head); printf("\nThe Result :\n"); outresult(m, stdout); getchar(); return 0; }
相关文章推荐
- Substring with Concatenation of All Words 字符串操作 匹配的字串数
- 关于Code Review
- java泛型
- (总结)HTTP常见错误返回代码
- 关于easyui datebox的记录
- WPF中的TreeView如何定义模版,并绑定数据
- Android - Data Binding
- AngularJS+Servlet跨域问题
- 曝光:Windows 10移动版系统被截图
- win7旗舰版如何运行jar文件
- 6.25 被虐记 3 期末测试 const
- Eclipse 调整背景色
- 如何提升你的能力?给年轻程序猿的几条建议
- QWidget类
- python类的继承
- 如何在Windows环境下运行Python脚本
- Myeclipse8.5中svn插件安装
- MySQL主从架构配置案例
- CWE-908: Use of Uninitialized Resource
- Win7下Eclipse中文字体太小解决