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. HTTP发展简史

    HTTP发展简史 HTTP协议是Hyper Text Transfer Protocol(超文本传输协议)的缩写,是用于从万维网(WWW:World Wide Web )服务器传输超文本到本地浏览器的 ...

  2. Python 字符串常用函数

    操作字符串的常用函数 函数 描述(返回值) str.capitalize() 将字符串的第一个字符大写 str.title() 返回标题化的字符串,即每个单词的首字母都大写 str.upper() 全 ...

  3. 微信小程序 - scroll-view的scroll-into-view属性 - 在页面打开后滚动到指定的项

    需求: 这是一个可横向滚动的导航条,现在要求我,从别的页面reLaunch回到首页这里,刷新页面内容的同时,菜单项要滚动出来 (如果该菜单项不在可视区域),而不是让他被挡住. 代码:<scrol ...

  4. Vim 中进行文件目录操作

    Vim 中进行文件目录操作 当前文件名 我们知道Vim有48个寄存器,其中%只读寄存器中保存着当前文件路径. 例如在/home/harttle/下打开src/main.cpp,我们打印%的值: :ec ...

  5. 【异常】[ERROR] The cloud assistant is not installed on the ECS, or the cloud assistant is unavailable. cloudassistant is uninstall

    一.异常信息 [INFO] Deployment File is Uploading... [INFO] IDE Version:IntelliJ IDEA [INFO] Alibaba Cloud ...

  6. 后台根据html邮件模板发送邮件

    HTML邮件模板: xxxxxxx 在线模板的方式: String fileName = "http://localhost:8080/xxxxxxx.html"; URL url ...

  7. linux启动介绍

    1. linux内核3.0之前,使用init(初始化 )进程管理的启动程序.一旦升级到3.0(centos7)使用systemd的方式进行管理. 2. 启动模式:启动后执行哪些典型的操作.vi/etc ...

  8. 软工团队第三次作业——编码组Alpha版本

    众志陈成组 柚荐--Alpha版本 编码部分 一.编码思路 思维导图如下 二.下载及操作方法 1.下载地址 GitHub地址:https://github.com/NyimaC/YouSuggest ...

  9. spring boot cli 知识点

    spring boot cli 版本列表: https://repo.spring.io/snapshot/org/springframework/boot/spring-boot-cli/ spri ...

  10. SQL编程规范整理

    一.排版规范 1.代码缩进 对于判断.循环等处理使用字符缩进 缩进的空格最好不要使用TAB键 2.空格及换行 变量定义.相对独立的程序块等要单独成行,便于阅读 太长的程序(超过110列)应做换行处理 ...