- 4
- 0
- 约3.82千字
- 约 10页
- 2017-08-18 发布于河南
- 举报
链表任意交换两个元素(Linked lists exchange two elements at will)
链表任意交换两个元素(Linked lists exchange two elements at will)
Algorithm function: the establishment of single linked list, exchange single chain table of the two elements.
3 * algorithm single chain table is the leading point of the node.
4 * function description: NOP
5 * @author:xiaoq-ohmygirl
6 * @time: 2012-06-20
7 **/
08.#include stdio.h
09.#include malloc.h
10.#include stdlib.h
11.#define MAXNODE 10
Twelve
13.typedef struct node{
14. int data;
15. node* next;
16.}*linkNode, *linkList;
Seventeen
Eighteen
19.// creates a single linked list with header nodes.
20.int createLinkList (linkList L, int, n) {
21. L = (linkList) malloc (sizeof (linkNode));
22. if ({L) {
23. return 0;
24.}
25. L-next = NULL;
26. linkList p;
27. for (int i = n; I 0; i--) {
28. P = (linkList) malloc (sizeof (linkNode));
29. scanf (%d, p-data);
30. p-next = L-next;
31. L-next = p;
32.}
33. return 1;
34.}
Thirty-five
36.void visit (linkNode, node) {
37. printf (%d-, node-data);
38.}
Thirty-nine
40.void, getNewLine () {
41. printf (\n);
42.}
43.// single linked list of leading nodes
44.void traverseLink (linkList, L) {
45. linkNode cur = L-next;
46. getNewLine ();
47. while (cur = = NULL) {
48. visit (cur);
49. cur = cur-next;
50.}
51. getNewLine ();
52.}
Fifty-three
Fifty-four
55.// looks for the first K node in the list.
56.linkNode findNode (const, linkList, L, int, K) {
57. linkNode node = L;
58. for (int = I = 1; i=k; i++) {
59. node = node-next;
60.}
61. return node;
62.}
Sixty-three
64.linkNode findPre (const, linkList, head, const, linkNode, node) {
65. linkNode TMP = head;
66. while (tmp-next = = node) {
67. TMP = tmp-next;
68.}
69. return tmp;
70.}
Seventy-one
72./*
73. * two nodes are exchanged according to the precursor of two nodes
74. * there are situations to consider:
75. * 1., if node 1 is the same as node 2, no interchange is required
76. * 2. if one of the nodes is the head node, it is not exchanged in principle
77. * 3. if two nodes are adjacent, you need to do some special proc
您可能关注的文档
- 谈汽车座椅设计(Design of automobile seat).doc
- 调光控制系统(Dimming control system).doc
- 谈电子商务对税收的冲击(The impact of Electronic Commerce on tax revenue).doc
- 谈如何做好公路填土路基施工的质量控制_pdf(How to do the quality control of highway fill subgrade construction _pdf).doc
- 谈设计对附加价值的意义(On the significance of design to additional value).doc
- 谈谈一堂好课的评价标准和如何备课(Talk about the evaluation criteria of a good lesson and how to prepare lessons).doc
- 谈谈中华文明的几个特点(Talking about several characteristics of Chinese civilization).doc
- 谈钻孔混凝土灌注桩施工质量控制要点(Key points of construction quality control of bored concrete filling pile).doc
- 谈钻孔灌注桩施工质量控制要点(Discussion on quality control points of bored pile construction).doc
- 谈矿山地质构造与瓦斯突出地段的控制(Talking about the control of mine geological structure and gas outburst).doc
- 铸件技术(Casting technology).doc
- 销售心态(Sales mindset).doc
- 铝塑板施工方案(Aluminum plate construction program).doc
- 定时器计数器简介(The timer counter.).doc
- 宝宝大便可判断疾病(Baby stool can determine the disease).doc
- 实习参考资料 考试记得准备(Remember to practice reference test).doc
- 宝宝情商培育全面计划表(Baby EQ fostering comprehensive plan table).doc
- 宝贝家族(Baby family).doc
- 实习周记四篇(Practice weekly four).doc
- 实习工作感想体会(Internship experience.).doc
最近下载
- 医疗器械特殊过程确认与灭菌确认.docx VIP
- 甘肃文旅行业深度报告:千年丝路如意甘肃,稳中有进高质量发展.docx
- ISO 9001:2026 (DIS) 中英文对照表.docx VIP
- 2025版14881-2025食品生产通用卫生规范专题培训教材.pptx
- (高清版)DB62∕T 3131-2017 戈壁沙漠地区光伏发电站施工规范.docx VIP
- 雨雪天气施工安全培训课件.pptx VIP
- 陕北剪纸艺术的图案特征与文化寓意.docx VIP
- 工商业储能一体机.pdf VIP
- 04S520埋地塑料排水管道施工图集.docx VIP
- 2023年注册土木工程师水利水电工程资格考试专业考试大纲 .pdf VIP
原创力文档

文档评论(0)