算法基础之链表
来源:互联网 发布:新东方软件 编辑:程序博客网 时间:2024/05/22 06:57
一、 抽象数据类型(ADT)
ADT是一些操作的集合,不涉及如何实现操作的集合,可以看作是模块化设计的扩充。
这些操作的实现只在程序中编写一次,而程序中任何其他部分需要在该ADT上运行其中的一种操作时可以通过调用适当的函数来进行
二、链表的一些操作
1.测试链表是否为空链表
int Isempty(List l){ return l->next=NULL;}
2.测试当前位置是否是链表的末尾函数
int Islast(Position p,List l){ return p->next=NULL;}
3.查找元素所在位置
Position Find(ElementType x,List l){ Position p; p=l->next; while(p!=NULL && p->element!=x) p=p->next; return p;}
4.删除元素
void Delete(ElementType x,List l){ Position p,temp; p=FindPrevious(x,l); if(!IsLast(p,l)) { temp=p->next; p->next=temp->next; free(temp); }}Position FindPrevios(ElementType x,List l){ //找到对应元素的前驱 Position p=l; while(p->next!=NULL && p->next->element!=x) { p=p->next; } return p;}
5.插入
void Insert(ElementType x,List l,Position p){ Position temp; temp=(Position)malloc(sizeof(Position)); if(temp == NULL) FatalError(“out of space!! ”); temp->element=x; if(p->next!=NULL) { temp->next=p->next; p->next=temp; } else { p->next=temp; temp->next=NULL; }}
6.删除链表(利用临时指针存储下一个元素,防止释放当前元素后找不到下一个元素)
void DelectList(List l){ Position p,temp; p=l->next;while(p!=NULL){ temp=p->next; free(p); p=temp;}
0 0
- 算法基础之链表
- 基础算法模板之链表+排序
- 找工作必备基础算法模板之链表+排序
- 算法基础之链表的游标实现
- 算法基础之基础数据结构
- 算法基础之排序算法
- 算法基础之递归算法
- 基础算法之贪心算法
- 算法基础之经典算法
- 基础算法之递推法
- 算法基础之排序
- 基础算法之排序
- 算法基础之字符串
- 算法基础之队列
- 算法基础之排序
- STL之算法基础
- 算法基础编之二分法
- 基础算法之二:递归
- Nginx的配置文件
- 进程通信之消息队列
- browser.cpp
- 阿里云Centos7使用yum安装MySQL5.6
- 直接拿来用,最火的.NET开源项目(beta)
- 算法基础之链表
- Java学习笔记(一)
- 精确率(准确率、查准率、precision)、召回率(查全率、recall)、RoC曲线、AUC面积、PR曲线
- 高性能mysql读书笔记1
- Windows下使用VisualSVN Server搭建SVN服务器
- STM32F412擦除内部FLASH时间过长
- 深入理解Java虚拟机1~内存区域与内存溢出
- tabwidget.h
- [POJ3130]How I Mathematician Wonder What You Are!(半平面交)