数据结构---无重复元素链表的实现
2016-01-26 18:59
441 查看
//节点结构体 struct inv { int i;//节点元素 struct inv*nextpointer; }; //返回指定元素节点的指针,不包含时返回NULL struct inv* contain(int i,struct inv*head) { struct inv *headp=head; while(headp!=NULL) { if(headp->i==i) { break; } headp=headp->nextpointer; } return headp; } //追加元素 int append(int i,struct inv **headpp) { struct inv *headp=*headpp; struct inv *prev; if(*headpp==NULL) { *headpp=(struct inv*)malloc(sizeof(struct inv)); (*headpp)->i=i; (*headpp)->nextpointer=NULL; return 1; } while(headp!=NULL) { prev=headp; if(headp->i==i) { return 0; } headp=headp->nextpointer; } prev->nextpointer=(struct inv*)malloc(sizeof(struct inv)); prev=prev->nextpointer; prev->i=i; prev->nextpointer=NULL; return 1; } //删除指定元素 int dele(int i,struct inv **headpp) { int returnvalue=0; struct inv*prev; struct inv*headp=*headpp; if(headp==NULL) { return 0; } while(headp->i!=i&&headp->nextpointer!=NULL) { prev=headp; headp=headp->nextpointer; } if(headp->i==i) { if(headp==*headpp) { *headp=*headp->nextpointer; } prev->nextpointer=headp->nextpointer; free(headp); return 1; } return 0; } //删除整个链表 void deleteall(struct inv**head) { struct inv*headp=*head; struct inv*temp; while(headp!=NULL) { temp=headp->nextpointer; free(headp); headp=temp; } *head=NULL; } //扫描打印 void paint(struct inv*headp) { while(headp!=NULL) { printf(" %d\n",headp->i); headp=headp->nextpointer; } }
cpp源码文件: http://pan.baidu.com/s/1bodkQRX
linked list.cpp文件
相关文章推荐
- 数据结构--栈的实现
- Nginx源码分析 - 基础数据结构篇 - 内存池 ngx_palloc.c
- 二叉排序树的实现
- 集合框架之常用Map实现类对比
- java数据结构详解
- 线段树系列(数据结构)
- 数组的理解与实现[数据结构]
- 数据结构基础之队列
- 小菜一步一步学数据结构之(六)队列
- 数据结构与算法的理解
- C++——数据结构之 顺序队列 链式队列?
- 数据结构->图的邻接表存储(C语言)
- 画金子塔算法
- PHP代码基本数据结构和php内置函数
- 二叉搜索树
- 数据结构实现之有序符号表BinarySearchST(使用有序数组的二分查找)
- 数据结构实现之无序符号表SequentialSearchST(使用链表实现)
- 数据结构实现之Table(符号表,内部存储key-value对)
- 数据结构(寒假小结)——2.1线性表之顺序表
- 小蚂蚁学习数据结构(24)——求二叉树深度和度为2的节点个数代码实现