数据结构-有序链表(基于简单链表)
2012-11-22 17:41
429 查看
/* * 文 件 名: OrdLinkList.java * 描 述: 有序链表 * 修改时间: 2012-11-22 */ package linklist; /** * 有序链表,按照关键字升序 */ public class OrdLinkList { private Link first; public OrdLinkList() { first = null; } /** * 判断链表是否为空 * * @return */ public boolean isEmpty() { return first == null; } /** * 按照整型key升序插入元素,规则为大于前一个元素,小于或者等于后一个元素 * @see [类、类#方法、类#成员] */ public void insertByAscend(int iData, double dData) { Link link = new Link(iData, dData); //如果链表为空,或键值比表头还小也做表头 if (isEmpty() || iData <= first.iData) { link.next = first; first = link; } else { Link current = first; Link next = current.next; while (iData > current.iData) { if (next == null || iData <= next.iData) { link.next = current.next; current.next = link; break; } current = next; next = current.next; } } } /** * 遍历链表 */ public void displayList() { Link current = first; while (current != null) { current.displayLink(); current = current.next; } } /** * 在链表头部删除元素 * * @return * @throws EmptyLinkListException */ public Link deleteFirst() throws EmptyLinkListException { if (isEmpty()) { throw new EmptyLinkListException(); } else { Link temp = first; first = first.next; return temp; } } }
相关文章推荐
- 数据结构_两个有序链表归并成新的链表(基于头插法建表与尾插法建表)
- 几种基本数据结构--栈、队列、双向链表、有根树的分析和简单实现
- 【数据结构_链表_最小堆】 链表找环,链表找交点,合并有序链表
- 简单数据结构--链表
- 数据结构学习的简单问题(三):用链表实现多项式相加
- (一)数据结构之线性表的简单实现:链表
- 【数据结构上机练习】4.链表的简单操作(2)
- 数据结构之简单链表(尾部插入数据)
- 数据结构:有序链表
- 重学数据结构 简单链表 倒叙,正序插入、常规显示、递归显示
- Java数据结构——有序链表
- 学习数据结构搜索的的意外收获哈。一个简单的基于java的网页抓取程序。
- 几种简单的数据结构的C++实现,树,图,链表,环形队列,栈等---环形队列篇
- 第13周 数据结构(上海交大) 6-2 两个有序链表归并
- 数据结构之简单链表(头部插入数据,查找,删除指定数据)
- 简单数据结构之双向链表(C++实现)
- 简单数据结构之链表(无头节点)
- 数据结构链表习题2.27,假设以两个元素依值递增有序排列的线性表A和B分别表示两个集合,现要求另辟空间构成一个顺序链表
- [C++]数据结构:有序链表SortedChain的基本实现与操作
- 数据结构之链表与数组(二) -单向链表上的简单操作问题