链表基本操作-包含详细代码结构-注释-运行结果截图

上传人:第*** 文档编号:33901814 上传时间:2018-02-19 格式:DOCX 页数:15 大小:229.96KB
返回 下载 相关 举报
链表基本操作-包含详细代码结构-注释-运行结果截图_第1页
第1页 / 共15页
链表基本操作-包含详细代码结构-注释-运行结果截图_第2页
第2页 / 共15页
链表基本操作-包含详细代码结构-注释-运行结果截图_第3页
第3页 / 共15页
链表基本操作-包含详细代码结构-注释-运行结果截图_第4页
第4页 / 共15页
链表基本操作-包含详细代码结构-注释-运行结果截图_第5页
第5页 / 共15页
点击查看更多>>
资源描述

《链表基本操作-包含详细代码结构-注释-运行结果截图》由会员分享,可在线阅读,更多相关《链表基本操作-包含详细代码结构-注释-运行结果截图(15页珍藏版)》请在金锄头文库上搜索。

1、/*name:linklist.hfunction:链表的基本操作author:huangwpdata:2015/6/03*/#ifndef _LINKLIST_H#define _LINKLIST_Hstruct datatypeint index;char l_string32;char l_char;float l_float;double l_double;struct node;typedef struct node *pnode;struct nodedatatype info;pnode link;typedef struct node *linklist;/*name:copy

2、_the_structinput_param:voidoutput:return;function:复制结构体*/void copy_the_struct( datatype *a, datatype value);/*name:creat_nulllist_with_headinput_param:voidoutput:return:成功:返回头链表的地址,失败:null;function:创建一个带头结点的空链表*/linklist creat_nulllist_with_head(void);/*name:is_null_listinput_param:链表的地址llistoutput:

3、return:0:空;1:非空;function:搬到*/int is_null_list(linklist llist);/*name:locate_valueinput_param:链表的地址llist,要找的数据value的索引output:return:所找数据所在的指针function:查找数据为value*/pnode locate_value(linklist llist, int l_index);/*name:locate_pre_valueinput_param:链表地址llist,节点p的地址output:return:节点p的前驱节点地址function:成功:查找p节

4、点所指向节点的前驱节点;失败:null*/pnode locate_pre_value(linklist llist, pnode p);/*name:insert_value_by_locateinput_param:链表地址llist,第几个位置插入i,值valueoutput:return:0,成功;-1:失败function:*/int insert_value_by_locate(int locate, datatype value);/*name:insert_value_by_addressinput_param:llist;address;valueoutput:return:

5、0:成功,-1失败function:在某个节点后面插入value*/int insert_value_by_address( pnode address, datatype value);/*name:insert_value_behindinput_param:llist;address;valueoutput:return:0:成功;-1:失败function:在链表尾部插入*/int insert_value_behind( pnode address, datatype value);/*name:insert_value_preinput_param:llist;address;va

6、lueoutput:return:0:成功;-1:失败function:在某节点前插入*/int insert_value_pre(linklist llist, pnode address, datatype value);/*name:delete_link_by_indexinput_param:llist;indexoutput:return:0:成功;-1:失败function:根据索引删除某个节点*/int delete_link_by_index(linklist llist, int index);/*name:delete_link_by_indexinput_param:l

7、list;indexoutput:return:0:成功;-1:失败function:单链表的整表删除*/int delete_link(linklist llist);/*name:delete_headinput_param:llist;indexoutput:return:0:成功;-1:失败function:删除头结点*/void delete_head(linklist llist);/*name:delete_headinput_param:pnodeoutput:return:0:function:打印链表*/void print(pnode pnode);#endif/ std

8、afx.h : 标准系统包含文件的包含文件,/ 或是经常使用但不常更改的/ 特定于项目的包含文件/#pragma once#include targetver.h#include linklist.h#include #include#include #include/ TODO: 在此处引用程序需要的其他头文件/*name:linklist.cppfunction:链表的基本操作author:huangwpdata:2015/6/03*/#include#include stdafx.hvoid copy_the_struct( datatype *dest, datatype *sourc

9、e)dest-index = source-index;dest-l_char = source-l_char;dest-l_double = source-l_double;dest-l_float = source-l_float;strcpy_s(dest-l_string, source-l_string);/*name:creat_nulllist_with_headinput_param:voidoutput:return:成功:返回头链表的地址,失败:null;function:创建一个带头结点的空链表*/linklist creat_nulllist_with_head(voi

10、d)linklist list = (linklist)malloc(sizeof(struct node);if(list != NULL)list-link = NULL;elseprintf(out of spacen);return list;/*name:is_null_listinput_param:链表的地址llistoutput:return:0:空;1:非空;function:搬到*/int is_null_list(linklist llist)return (llist-link = NULL);/*name:locate_valueinput_param:链表的地址ll

11、ist,要找的数据value的索引output:return:所找数据所在的指针function:查找数据为value*/pnode locate_value(linklist llist, int l_index)pnode p = NULL;if( llist = NULL)printf(locate_value fail, llist is NULLn);return NULL;p = llist;while(p-link!= NULL) & (p-link-info.index != l_index)p=p-link;if(p-link!=NULL)printf(find it p-i

12、nfo.index = %dn, p-link-info.index);return p-link;elseprintf( do not find it p-info.indexn);return NULL;/*name:locate_pre_valueinput_param:链表地址llist,节点p的地址output:return:节点p的前驱节点地址function:成功:查找p节点所指向节点的前驱节点;失败:null*/pnode locate_pre_value(linklist llist, pnode p)pnode p1 = NULL;if(llist = NULL)print

13、f(locate_pre_value fail,llist is nulln);return NULL;p1 = p;while(p1 != NULL)&(p1-link != p)p1 = p1-link;return p1;/*name:insert_value_by_locateinput_param:链表地址llist,第几个位置插入i,值valueoutput:return:0,成功;-1:失败function:*/int insert_value_by_locate(linklist llist, int locate, datatype value)return 0;/*name

14、:insert_value_by_addressinput_param:llist;address;valueoutput:return:0:成功,-1失败function:在某个节点后面插入value*/int insert_value_by_address(pnode address, datatype value)pnode q = (pnode)malloc(sizeof(struct node);if(q = NULL)printf(out of the space n);return -1;copy_the_struct(q-link = address-link;address-link = q;return 0;/*name:insert_value_behindinput_param:llist;address;valueoutput:return:0:成功;-1:失败function:在链表尾部插入*/int insert_value_behind(pnode address, datatype value)pnode r = NULL;pnode m =

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 办公文档 > 解决方案

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号