func-package

函数库, 面向复杂业务场景的 js 类库

BothLinkedList

双向链表

bothLinkedList.insertHead(param): param 是 需要插入的元素,插入到元素链表尾部
bothLinkedList.insertIndex(param, index): param 是 需要插入的元素,index: 需要插入的位置
bothLinkedList.getHead(): 从头开始遍历链表
bothLinkedList.getTail(): 从尾开始遍历链表
bothLinkedList.getData(index): index: 通过索引获取元素值
bothLinkedList.getSize(): 获取链表长度
bothLinkedList.deleteFrom(index): index 通过索引删除元素节点
bothLinkedList.deleteData(param): index 通过元素值删除元素节点

返回值:Node 类型:

{ data: 1, next: undefined, prev: undefined }

Demo:

import { BothLinkedList } from 'func-package';
let bothLinkedList = new BothLinkedList()
bothLinkedList.insertHead(1);
bothLinkedList.insertHead(2);
// bothLinkedList.insertHead(3)
console.log(bothLinkedList.getHead())
bothLinkedList.deleteFrom(1)
bothLinkedList.deleteData(1)
console.log(bothLinkedList.getHead())
// console.log(bothLinkedList.getTail())
// console.log(bothLinkedList.getData(3))