玄冬aigo.blog.chinaunix.net
escarp
全部博文(347)
OpenGLES(1)
DirectX(5)
OpenGL(2)
错误处理(3)
Java优化(5)
IDE相关(0)
Java基础(1)
JVM(2)
ACE(1)
GDI(1)
MFC(1)
Boost(1)
STL(4)
2016年(1)
2013年(4)
2012年(207)
2011年(85)
2010年(50)
tian_ye
zkj_tz
n73man00
RHUB网络
无赖皮肤
dragonfl
曾德标
Larpente
CU官方博
大镇
jinjianl
wxg15974
cynthia
Bsolar
格伯纳
浪花小雨
gbaidu20
stuyou
分类:
2010-07-30 00:19:23
package com.black.datastructures.link;/** * 链接点 * * @author BlackWinter * * @date 2010-7-7 下午10:45:24 * * @file com.black.datastructures.link.Link.java * * @version 1.0 */public class Link { public int key; public double value; public Link next; public Link(int id, double date) { this.key = id; value = date; } public void displayLink() { System.out.printf("{%s,%s}\n", key, value); }}
package com.black.datastructures.link;/** * 单向链表 * * @author BlackWinter * * @date 2010-7-7 下午10:35:10 * * @file com.black.datastructures.link.LinkList.java * * @version 1.0 */public class LinkList { private Link first; public LinkList() { first = null; } public boolean isEmpty() { return first == null; } /* 在链表头部插入新节点 */ public void insertFirst(int id, double date) { Link link = new Link(id, date); link.next = first; first = link; } /* 删除链表的头部节点 */ public Link deleteFirst() { Link temp = first; first = first.next; return temp; } /* 根据key查询指定的链接点 */ public Link find(int key) { Link current = first; while (current.key != key) { if (current.next == null) return null; else current = current.next; } return current; } /* 根据key删除指定节点 */ public Link delete(int key) { Link current = first; Link previous = first; while (current.key != key) { if (current.next == null) return null; else { current = current.next; previous = current; } } if (current == first) first = first.next; else previous.next = current.next; return current; } /* 显示链表的所有节点 */ public void displayList() { System.out.println("First --> Last:"); Link current = first; while (null != current) { current.displayLink(); current = current.next; } }}
package com.black.datastructures.link;/** * 双端链表 * * @author BlackWinter * * @date 2010-7-11 下午09:09:12 * * @file com.black.datastructures.link.DouEndLinkList.java * * @version 1.0 */public class DouEndLinkList { private Link first; private Link last; public DouEndLinkList() { first = null; last = null; } public boolean isEmpty() { return first == null; } public void insertFirst(int id, double date) { Link newLink = new Link(id, date); if (isEmpty()) last = newLink; newLink.next = first; first = newLink; } public void insertLast(int id, double date) { Link newLink = new Link(id, date); if (isEmpty()) first = newLink; else last.next = newLink; last = newLink; } public void display() { System.out.println("List (first --> last):"); Link current = first; while (null != current) { current.displayLink(); current = current.next; } }}
上一篇:没有了
下一篇:PowerDesigner属性设置笔记
登录 注册