DLCL

双向循环链表

源码

https://github.com/ddzy/ts-utility-plugins/tree/master/src/ddzy/utility/algorithm/double-linked-circular-list

说明

双向循环链表插件‌, 源码地址:

https://github.com/ddzy/ts-utility-plugins/tree/master/src/ddzy/utility/algorithm/double-linked-circular-list

用法

index.ts
const dlcl = new utilityAlgorithm.DLCL<number>({
nodes: [2, 5, 8, 3, 7, 19, 23, 14, 41],
});
// ? handleGetHead
console.log(dlcl.handleGetHead());
// ? handleGetTail
console.log(dlcl.handleGetTail());
// ? handleAppend
console.log(dlcl.handleGetTail());
dlcl.handleAppend(-1).handleAppend(-2);
console.log(dlcl.handleGetTail());
// ? handlePrepend
console.log(dlcl.handleGetHead());
dlcl.handlePrepend(-1).handlePrepend(-2);
console.log(dlcl.handleGetHead());
// ? handleInsertBefore
dlcl.handleInsertBefore(8, 100);
dlcl.handleInsertBefore(2, 100);
dlcl.handleInsertBefore(41, 100);
console.log(dlcl.handleGetHead());
console.log(dlcl.handleGetTail());
// ? handleInsertAfter
dlcl.handleInsertAfter(41, 200);
console.log(dlcl.handleGetTail());
dlcl.handleInsertAfter(41, 100);
console.log(dlcl.handleGetLength());
console.log(dlcl.handleGetTail());
dlcl.handleInsertAfter(8, 200);
console.log(dlcl.handleGetHead());
// ? handleTraversalWithForward
dlcl.handleTraversalWithForward((node) => {
console.log(node);
});
// ? handleTraversalWithBackward
dlcl.handleTraversalWithBackward((node) => {
console.log(node);
});
// ? handleGetLength
dlcl.handleAppend(100).handleAppend(200);
dlcl.handlePrepend(100).handlePrepend(200);
dlcl.handleInsertBefore(2, 100).handleInsertBefore(100, 200);
dlcl.handleInsertAfter(41, 100);
console.log(dlcl.handleGetLength());
// ? handleRemove
dlcl.hanldeRemove(2);
dlcl.hanldeRemove(41);
dlcl.handleRemove(5);
dlcl.handleRemove(5).handleAppend(5).handleRemove(5);
console.log(dlcl.handleGetHead());
console.log(dlcl.handleGetTail());
console.log(dlcl.handleGetLength());

API

Name

Value

Description

handleGetHead

() => ListNode<V>

获取节点

handleGetTail

() => ListNode<V>

获取节点

handleGetLength

() => number

获取链表长度

handleAppend

(value: V) => DoubleLinkedCircularList<V>

追加节点到链表尾部

handlePrepend

(value: V) => DoubleLinkedCircularList<V>

追加节点至链表首部

handleInsertBefore

(target: V, value: V) => DoubleLinkedCircularList<V>

新节点插入到指定节点

handleInsertAfter

(target: V, value: V) => DoubleLinkedCircularList<V>

新节点插入到指定节点

handleRemove

(value: V) => DoubleLinkedCircularList<V>

移除指定节点

handleTraversalWithForward

((node: ListNode<V>) => void) => void

正向遍历链表

handleTraversalWithBackward

((node: ListNode<V>) => void) => void

反向遍历链表