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. 微信小程序必知相关知识

    微信小程序必知相关知识 1 请谈谈微信小程序主要目录和文件的作用? project.config.json 项目配置文件,用得最多的就是配置是否开启https校验: App.js 设置一些全局的基础数 ...

  2. 使用EF Core+CodeFirst建立ASP.NET Core MVC项目

    本篇随笔介绍如何使用.NET Core+EF Core创建Web应用程序 首先借用官网的话简单介绍一下ASP.NET Core ASP.NET Core 是一个跨平台的高性能开源框架,用于生成基于云且 ...

  3. 全面了解Cookie

    一.Cookie的出现 浏览器和服务器之间的通信少不了HTTP协议,但是因为HTTP协议是无状态的,所以服务器并不知道上一次浏览器做了什么样的操作,这样严重阻碍了交互式Web应用程序的实现. 针对上述 ...

  4. Python3 import tensorflow 出现FutureWarning: Passing (type, 1) or '1type' 问题

    解决python调用TensorFlow时出现FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecate ...

  5. MongoDB分片,唯一索引与upsert

    前言 分片,唯一索引和upsert,表面上看似没有直接联系的几个东西,到底存在怎样的瓜葛呢? 分片 为了保持水平扩展的有效性,分片功能必须保证各个片之间没有直接关联,不需要与其他分片交互就可以独立做出 ...

  6. linux磁盘空间满了 但是没有大文件

    很常见的一个问题 linux磁盘空间满了 但是没有大文件 解决思路: 1.用df 检查发现/根目录可用空间为0 [root@/]#df -h 2.用du检查发现各目录占用的空间都很少,有约3G的空间莫 ...

  7. Apache/Nginx的web网页访问加密

  8. 记录一次win2003服务器的IIS服务加载.flv后缀的资源报错404的处理方法

    问题:访问某个域名下的xxxx.flv资源,页面报错404. 解决思路: 1.权限是否给足 user权限给完全控制咯 如果你访问该域名下的其他资源无问题的话就不是介个原因了 2.MIME类型是否少了 ...

  9. 基于SCRUM方法实践的西油计科党建设计与实现-个人实践流程清单

    基于SCRUM方法实践的西油计科党建设计与实现 个人实践流程清单 一.Alpha版本冲刺个人在SCRUM团队任务清单: 时间 我这个三天做了什么 实际解决燃尽图项目数量 我遇到了什么问题 我下一个三天 ...

  10. Linq入门学习

    千万别被这个页面的滚动条吓到!!! 我相信你一定能在30分钟之内看完它!!! 在说LINQ之前必须先说说几个重要的C#语言特性 一:与LINQ有关的语言特性 1.隐式类型 (1)源起 在隐式类型出现之 ...