链表基本操作-包含详细代码结构-注释-运行结果截图.docx_第1页
链表基本操作-包含详细代码结构-注释-运行结果截图.docx_第2页
链表基本操作-包含详细代码结构-注释-运行结果截图.docx_第3页
链表基本操作-包含详细代码结构-注释-运行结果截图.docx_第4页
链表基本操作-包含详细代码结构-注释-运行结果截图.docx_第5页
已阅读5页,还剩10页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

/*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_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: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节点所指向节点的前驱节点;失败: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: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;valueoutput: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:llist;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/ stdafx.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 *source)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(void)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:链表的地址llist,要找的数据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-info.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)printf(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: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-info, &value);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 = NULL;pnode q = (pnode)malloc(sizeof(struct node);if(q = NULL)printf(out of the space n);return -1;copy_the_struct(&q-info, &value);r = address;m = address;while(r-link != NULL)r = r-link;q-link = NULL; r-link = q;while(m-link!=NULL)printf(insert_value_behind = %dn,m-link-info.index);m=m-link;printf(=n);locate_value(address, 10);/*name:insert_value_preinput_param:llist;address;valueoutput:return:0:成功;-1:失败function:在某个借点钱插入*/int insert_value_pre( pnode address, datatype value)return 0;/*name:delete_link_by_indexinput_param:llist;indexoutput:return:0:成功;-1:失败;1:不存在function:根据索引删除某个节点*/int delete_link_by_index(linklist llist, int index)pnode p = NULL;pnode q = NULL;if( llist = NULL)printf(locate_value fail, llist is NULLn);return NULL;p = llist;while(p-link!= NULL) & (p-link-info.index != index)p=p-link;if(p-link!=NULL)printf(find it p-info.index = %dn, p-link-info.index);printf(find it p-info.index = %dn, p-info.index);q = p-link;p-link = q-link;free(q);return 0;elseprintf( do not find it p-info.indexn);return -1;/*name:delete_link_by_indexinput_param:llist;indexoutput:return:0:成功;-1:失败function:单链表的整表删除*/int delete_link(linklist llist)linklist p = NULL;linklist q = NULL;while(p)q=p-link;free(p);p=q;llist-link = NULL;return 0;/*name:delete_headinput_param:llist;indexoutput:return:0:成功;-1:失败function:删除头结点*/void delete_head(linklist llist)free(llist);/*name:delete_headinput_param:pnodeoutput:return:0:function:打印链表*/void print(pnode node) pnode p = NULL;p = node;int i = 0;while(p-link!= NULL)/printf(list-l_string= %sn, p-info.l_string);printf(list-index = %d,i = %dn, p-link-info.index,i);p = p-link

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论