1、结构:

2、Link代码:

public class Link {

	public int iData;
public double dData;
public Link next; public Link(int id,double dd){
iData = id;
dData = dd;
} public void displayLink(){
System.out.println("{" + iData + " , " + dData + " } ");
} }

3、LinkList代码:

public class LinkList {

	private Link first;

	public LinkList(){
first = null;
} public boolean isEmpty(){
return (first == null);
} public void insertFirst(int id, double dd){
Link newLink = new Link(id, dd);
newLink.next = first;
first = newLink;
} public Link deleteFirst(){
Link temp = first;
first = first.next;
return temp;
} public void displayList(){
System.out.println("List (first -- > last);");
Link current = first;
while(current != null){
current.displayLink();
current = current.next;
}
System.out.println(" ");
} public Link find(int key){
Link current = first;
while(current.iData != key){
if(current.next == null){
return null;
}else{
current = current.next;
}
}
return current;
} public Link delete(int key){
Link current = first;
Link previous = first;
while(current.iData != key){
if(current.next == null){
return null;
}else{
previous = current;
current = current.next;
}
}
if(current == first){
first = first.next;
}else{
previous.next = current.next;
}
return current;
} }

4、运行代码:

public class LinkList2App {

	public static void main(String[] args) {
LinkList theList = new LinkList(); theList.insertFirst(22, 2.99);
theList.insertFirst(44, 4.99);
theList.insertFirst(66, 6.99);
theList.insertFirst(88, 8.99); theList.displayList(); Link f = theList.find(44);
if(f != null){
System.out.println("Found link with key " + f.iData);
}else{
System.out.println("Can't find link");
} Link d = theList.delete(66);
if( d != null){
System.out.println("Deleted link with key " + d.iData);
}else{
System.out.println("Can't delete link");
} theList.displayList(); }
}

5、结果:

List (first -- > last);
{88 , 8.99 }
{66 , 6.99 }
{44 , 4.99 }
{22 , 2.99 } Found link with key 44
Deleted link with key 66
List (first -- > last);
{88 , 8.99 }
{44 , 4.99 }
{22 , 2.99 }

Reference:

[1] Robert Lalore(著) 计晓云,赵研,曾希,狄小菡(译), Java数据结构和算法(第二版),中国电力出版社,2004 :131-150

数据结构之LinkList的更多相关文章

  1. [数据结构]链表LinkList

    目录 1.3 链表 1.3.1 头插法建立单链表 1.3.2 限制链表长度建立单链表 1.3.3 尾插法建立单链表 1.3.4 按序号查找单链表 1.3.5 按值查找单链表 1.3.6 链表的插入 1 ...

  2. java容器的数据结构-ArrayList,LinkList,HashMap

    ArrayList: 初始容量为10,底层实现是一个数组,Object[] elementData 自动扩容机制,当添加一个元素时,数组长度超过了elementData.leng,则会按照1.5倍进行 ...

  3. Java:List,ArrayList和LinkList的区别

    1.大学数据结构中ArrayList是实现了基于动态数组的数据结构,LinkList基于链表的数据结构 2.对于随机访问get和set,ArrayList优于LinkList,因为LinkedList ...

  4. Android——ArrayList 、LinkList、List 区别 & 迭代器iterator的使用 & HashMap、Hashtable、LinkedHashMap、TreeMap

     ArrayList .LinkList.List 区别 & 迭代器iterator的使用 & HashMap.Hashtable.LinkedHashMap.TreeMap 一.几个 ...

  5. JAVA框架面试题

    至少写出3种ssh框架中常用的注解 @RequestMapping springMvc中访问地址映射 @ResponseBody springMvc中返回视图 @Table hibernate中实体类 ...

  6. Junit 注解 类加载器 .动态代理 jdbc 连接池 DButils 事务 Arraylist Linklist hashset 异常 哈希表的数据结构,存储过程 Map Object String Stringbufere File类 文件过滤器_原理分析 flush方法和close方法 序列号冲突问题

    Junit 注解 3).其它注意事项: 1).@Test运行的方法,不能有形参: 2).@Test运行的方法,不能有返回值: 3).@Test运行的方法,不能是静态方法: 4).在一个类中,可以同时定 ...

  7. [数据结构]链表相关的实现LinkList.cpp

    目录 LinkList.cpp //链表相关操作的实现 LinkList.h LinkListManager.cpp //链表相关实现函数的调用 LinkListManager.h LinkList. ...

  8. 数据结构自己实现——Linklist

    //单???链???表??? #include <iostream> using namespace std; typedef char datatype; typedef struct ...

  9. Java数据结构与算法(5) - ch05链表(LinkList)

    双端链表与传统链表非常相似,但是它有一个新增的特性:即对最后一个链节点的引用,就像对第一个连接点的引用一样.注意与双向链表进行区别.

随机推荐

  1. Java自学-数字与字符串 比较字符串

    Java 比较字符串 示例 1 : 是否是同一个对象 str1和str2的内容一定是一样的! 但是,并不是同一个字符串对象 package character; public class TestSt ...

  2. BUAA-OO-2019 第三单元总结

    JML语言理论基础梳理及工具链 注释结构 JML以javadoc注释的方式来表示规格,每行都以@起头. 行注释://@annotation 块注释:/* @ annotation @*/ JML表达式 ...

  3. npm升级到最新版本、指定版本

    npm 升级到最新版本 //linux下 npm install -g npm npm升级到指定版本 //比如升级到5.6.0 npm install -g npm@5.6.0

  4. 30、filter数组去重

    eg: let arr=[1,0,0,9,7,7,5,2] let data=arr.filter((item,index,self)=> self.indexOf(item)===index ...

  5. Android编译系统中的Android.bp

    https://www.cnblogs.com/bluestorm/p/10895005.html Android.bp,是用来替换Android.mk的配置文件. 它使用Blueprint框架来解析 ...

  6. Android-----创建SQLite数据库

    简单介绍一下Android系统内置轻便又功能强大的嵌入式数据库--SQLite. SQLite是D.Richard Hipp用C语言编写的开源嵌入式数据库引擎,它是一款轻型的数据库,是遵守ACID的关 ...

  7. MongoDB的集群模式--Sharding(分片)

    分片是数据跨多台机器存储,MongoDB使用分片来支持具有非常大的数据集和高吞吐量操作的部署. 具有大型数据集或高吞吐量应用程序的数据库系统可能会挑战单个服务器的容量.例如,高查询率会耗尽服务器的CP ...

  8. BBS之文章详情页搭建

    博客评论相关 博客文章详情页搭建 {% extends 'base.html' %} {% block css %} <style> #div_digg { float: right; m ...

  9. 团队——Beta版本发布

    目录 最棒团队成员信息 一.7次冲刺博客链接 二.解决的Alpha版本问题 / Beta计划任务(与Alpha版本不同点) 二.项目本次α版本的发布地址.下载安装说明 四.PM最终报告(详细报告在各冲 ...

  10. HttpRunner V2.x 学习(一)

    官方说明文档: https://cn.httprunner.org/ 作者(李隆)博客: https://debugtalk.com/ 1.介绍 HttpRunner 是一款面向 HTTP(S) 协议 ...