1 Star 6 Fork 1

蔚蔚樱软件开发/AlgoHub

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
DuplexListljImpl.java 1.82 KB
一键复制 编辑 原始数据 按行查看 历史
ljfirst 提交于 2022-11-11 15:41 +08:00 . feat:LRU LFU
package DataStructure.list.hashTable;
import DataStructure.list.Nodelj;
/**
* @author 蔚蔚樱
* @version 1.0
* @date 2020/7/28
* @author—Email micromicrohard@outlook.com
* @blogURL https://blog.csdn.net/Micro_Micro_Hard
* @description cache 双向链表
*/
public class DuplexListljImpl implements DuplexListlj {
//链表头尾指针,链表的实际长度
Nodelj head;
Nodelj tail;
int linkedSize;
//初始化 双向链表
public DuplexListljImpl() {
this.head = new Nodelj();
this.tail = new Nodelj();
this.head.next = this.tail;
this.tail.front = this.head;
}
//增加元素(链表尾部)
public boolean insertLast(Nodelj node) {
//空链表的处理方法
if (head.next == tail) {
head.next = node;
node.front = head;
} else {
tail.front.next = node;
node.front = tail.front;
}
linkedSize++;
node.next = tail;
tail.front = node;
return true;
}
//删除元素
public boolean delete(Nodelj node) {
node.next.front = node.front;
node.front.next = node.next;
linkedSize--;
return true;
}
//删除并返回 首元素
public Nodelj deleteOld() {
if (head.next == tail) {
return null;
}
Nodelj first = head.next;
delete(first);
return first;
}
//返回 链表最后一个元素【最新插入的】
public Nodelj getLeast() {
if (head.next == tail) {
return null;
}
return tail.front;
}
//获取双向链表的长度
public int getSize() {
return this.linkedSize;
}
//双向链表是否为空
public boolean isEmpty() {
return this.head.next == this.tail;
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/micromicrohard/algo-hub.git
git@gitee.com:micromicrohard/algo-hub.git
micromicrohard
algo-hub
AlgoHub
master

搜索帮助