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. 架构在APP和前端里的应用和演进

    架构设计相关的理念.技术.实践,比如存储高可用.微服务.异地多活等,都是后端系统才会涉及.事实上确实也是如此,通常情况下我们讲架构设计,主要聚焦在后端系统,但这并不意味着 App.前端就没有架构设计了 ...

  2. BIO,NIO和AIO

    BIO:同步阻塞式IO,服务器实现模式为一个连接一个线程,即客户端有连接请求时服务器端就需要启动一个线程进行处理,如果这个连接不做任何事情会造成不必要的线程开销,当然可以通过线程池机制改善. NIO: ...

  3. json教程系列(1)-使用json所要用到的jar包下载

    json是个非常重要的数据结构,在web开发中应用十分广泛.我觉得每个人都应该好好的去研究一下json的底层实现,基于这样的认识,金丝燕网推出了一个关于json的系列教程,分析一下json的相关内容, ...

  4. java MD5Utils 加密工具类

    package com.sicdt.library.core.utils; import java.io.File; import java.io.FileInputStream; import ja ...

  5. freopen重定向输入

    #include <bits\stdc++.h> using namespace std; int main() { freopen("C:\\Users\\dcf\\Deskt ...

  6. nginx常见面试题1

    Nginx是网页服务器运维人员不可能绕开的一个弯,剩下几个比较高危的面试范围是:linux基础.网络知识基础.python,或许还会有zabbix等监控工具.这里先说nginx,后面几个肯定也会写. ...

  7. utf-8,Unicode和ASCII区别

    一.ASCII 码 我们知道,计算机内部,所有信息最终都是一个二进制值.每一个二进制位(bit)有0和1两种状态,因此八个二进制位就可以组合出256种状态,这被称为一个字节(byte).也就是说,一个 ...

  8. XXL-Job分布式任务调度

    分布式情况下定时任务会出现哪些问题? 分布式集群的情况下,怎么保证定时任务不被重复执行 分布式定时任务解决方案 ①使用zookeeper实现分布式锁 缺点(需要创建临时节点.和事件通知不易于扩展) ② ...

  9. MapReduce-shuffle过程详解

    Shuffle map端 map函数开始产生输出时,并不是简单地将它写到磁盘.这个过程很复杂,它利用缓冲的方式写到内存并出于效率的考虑进行预排序.每个map任务都有一个环形内存缓冲区用于存储任务输出. ...

  10. BASE64Encoded() 方法报错说方法未定义

    代码: String enParams = new BASE64Encoder().encode(strParams.getBytes()); 出错,显示方法未定义 解决方法:项目右键——>pr ...