[Java]单项链表与双端链表[原]
2016-01-25 16:23
316 查看
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; } } } |
<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"16"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script>
阅读(558) | 评论(0) | 转发(0) |
0
上一篇:没有了
下一篇:国外威客网站大盘点
相关热门文章
A sample .exrc file for vi e...
游标的特征
IBM System p5 服务器 HACMP ...
busybox的httpd使用CGI脚本(Bu...
Solaris PowerTOP 1.0 发布
linux dhcp peizhi roc
关于Unix文件的软链接
求教这个命令什么意思,我是新...
sed -e "/grep/d" 是什么意思...
谁能够帮我解决LINUX 2.6 10...
给主人留下些什么吧!~~
评论热议
相关文章推荐
- [Java]单项链表与双端链表[原]
- github and eclipse
- SpringMVC表单标签&处理静态资源
- Java基础学习7_类和对象
- Eclipse将引用了第三方jar包的Java项目打包成jar文件的两种方法
- Java 入门 之 字符串与异常处理
- OpenCV配置(Java)
- 【慕课笔记】U1 类和对象 第2节 如何定义JAVA中的类
- CDH5 Integration with Eclipse
- quartz+spring 实现任务调度
- Spring MVC 教程,快速入门,深入分析
- 使用GitHub for Eclipse管理项目。
- JAVA反射机制
- 编译 Hadoop Eclipse Plugin
- Thinking in Java,Fourth Edition(Java 编程思想,第四版)学习笔记(十四)之Type Information
- java基础篇--10<java多线程>
- Eclipse版本查看
- Note:This element neither has attached source nor attached Javadoc
- Note:This element neither has attached source nor attached Javadoc
- Java transient关键字使用小记