public class doubleLinkedList <Item>{

    private Node first;
private Node last;
private int itemcount;
class Node{
Node prev;
Node next;
Item item; } public void addFirst(Item item){
Node oldfirst=first;
first=new Node();
first.item=item;
first.next=oldfirst;
if(oldfirst!=null){ oldfirst.prev=first; } if(itemcount==0){ last=first;
}
itemcount++;
} public void addlast(Item item){ Node oldlast=last;
last=new Node();
last.item=item;
last.prev=oldlast; if(oldlast!=null){ oldlast.next=last;
} if(itemcount==0){ last=first;
} itemcount++;
}
//
public Item delfirst(){
if(first==null){
throw new NullPointerException("no node linked list");
}
Item item=first.item;
first=first.next;
if(first!=null){ first.prev=null;
} if(itemcount==1){ last=null;
}
itemcount--;
return item; } public Item dellast(){ if(last==null){
throw new NullPointerException("no node this linked");
}
Item item =last.item;
last=last.prev; if(last!=null){ last.next=null; }
if(itemcount==1){ first=null;
}
itemcount--;
return item; } //
public void addbefore(Item targetItem,Item item){ Node target=first;
if(target==null){ throw new NullPointerException("no node this linked");
} if(target!=null && target.item!=targetItem){ target=target.next;
} if(target.prev==null){ addFirst(item);
}
else{
Node targetprev=target.prev;
Node newtarget=new Node();
newtarget.item=item;
target.prev=newtarget;
newtarget.next=target;
newtarget.prev=targetprev;
targetprev.next=newtarget; itemcount++;
}
} //
public void addafter(Item targetItem,Item item){ Node target =first;
if(target==null){ throw new NullPointerException("no node this linked!"); }
if(target!=null && target.item!=targetItem){
target=target.next; }
if(target.next==null){ addlast(item);
}
else{ Node oldtarget=target.next;
Node newnode=new Node();
newnode.item=item;
newnode.next=oldtarget;
oldtarget.prev=newnode;
target.next=newnode;
newnode.prev=target; itemcount++;
} }
}

双向链表(Double-Linked List)的更多相关文章

  1. Linux C double linked for any data type

    /************************************************************************** * Linux C double linked ...

  2. 数据结构(C++)之Double Linked List实践

    //double linked list (type int),the position starts from 0 #include <iostream> using namespace ...

  3. java数据结构——单链表、双端链表、双向链表(Linked List)

    1.继续学习单链表,终于摆脱数组的魔爪了,单链表分为数据域(前突)和引用域(指针域)(后继),还有一个头结点(就好比一辆火车,我们只关心火车头,不关心其它车厢,只需知晓车头顺藤摸瓜即可),头结点没有前 ...

  4. javascript实现数据结构与算法系列:循环链表与双向链表

    循环链表(circular linked list) 是另一种形式的链式存储结构.它的特点是表中最后一个结点的指针域指向头结点,整个表形成一个环. 循环链表的操作和线性链表基本一致,仅有细微差别. w ...

  5. C++ Templates STL标准模板库的基本概念

    STL标准库包括几个重要的组件:容器.迭代器和算法.迭代器iterator,用来在一个对象群集的元素上进行遍历操作.这个对象群集或许是一个容器,或许是容器的一部分.迭代器的主要好处是,为所有的容器提供 ...

  6. stl源码剖析 详细学习笔记priority_queue slist

    // //  priority_queue.cpp //  笔记 // //  Created by fam on 15/3/16. // // //------------------------- ...

  7. complexity_action

    大话数据结构 /* 顺序存储的结构 */ #define MAXSIZE 20 //存储空间初始分配量 typedef int ElemType; //ElemType类型根据实际情况而定,这里假设为 ...

  8. [DT] 数据结构术语中英文对照

    数据结构术语中英文对照 数据 Data 数据元素 Data element 数据项 Data item 数据结构 Data structure 逻辑结构 Logical structure 数据类型 ...

  9. .Net Core使用分布式缓存Redis:数据结构

    一.前言 本篇主要使用StackExchangeRedis在.Net Core中使用Redis,使用基础见:点击此处. 二.五种基础数据结构 1.字符串类型String 字符串类型是Redis中最基本 ...

  10. 分布式架构-Redis 从入门到精通 完整案例 附源码

    导读 篇幅较长,干货十足,阅读需要花点时间,全部手打出来的字,难免出现错别字,敬请谅解.珍惜原创,转载请注明出处,谢谢~! NoSql介绍与Redis介绍 什么是Redis? Redis是用C语言开发 ...

随机推荐

  1. Java访问网络url,获取网页的html代码

    在Java中,Java.net包里面的类是进行网络编程的,其中,java.net.URL类和java.net.URLConection类是编程者方便地利用URL在Internet上进行网络通信.有两种 ...

  2. LVS 介绍

    LVS 介绍 说明: LVS是Linux Virtual Server的简称 LVS是一个实现负载均衡的开源软件项目 LVS效率要高于Nginx LVS工作在ISO的第4层(传输层) LVS架构有三层 ...

  3. 主攻ASP.NET MVC4.0之重生:Jquery Mobile 表单元素

    相关代码: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <tit ...

  4. mongodb中的__v字段

    "__v"是"versionKey"的简写,当每一个文档由mongoose创建时就会自动添加,代表这该文档的版本,此属性可配置修改,默认为"__v&q ...

  5. Go Log模块生成日志文件

    使用log模块示例代码: package main import ( "fmt" "time" "log" "os" ) ...

  6. JAVA 使用qq邮箱发送邮件

    引入一个架包: gradle( "com.sun.mail:javax.mail:1.5.6", ) 代码如下: private static final String QQ_EM ...

  7. CentOs linux安装SVN服务

    SVN服务器有2种运行方式:1.独立服务器(例如:svn://xxx.com/xxx):2.借助apache   (例如:http://svn.xxx.com/xxx):为了不依赖apache,我选择 ...

  8. Struts2的<s:date>标签使用详解[转]

    作用:用来格式化显示日期的格式. 它可以用一种你指定的格式来显示 (如:“yyyy-MM-dd”),可以生成通俗易懂的注释(如:in 2 hours,14 minutes),或者用预先定义的一个格式来 ...

  9. 4.JDBC编程

    01.JDBC_Java程序和MySQL的关系:     1).Java程序跟其它MySQL客户端一样,就是一个"客户端",用于"封装SQL语句"并发送给MyS ...

  10. sql server deadlock problem

    https://www.red-gate.com/simple-talk/sql/learn-sql-server/how-to-track-down-deadlocks-using-sql-serv ...