https://github.com/postor/double-linked-sorted-tree
double linked sorted tree
https://github.com/postor/double-linked-sorted-tree
Last synced: 2 months ago
JSON representation
double linked sorted tree
- Host: GitHub
- URL: https://github.com/postor/double-linked-sorted-tree
- Owner: postor
- License: mit
- Created: 2022-04-25T03:31:52.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-04-28T03:37:09.000Z (about 3 years ago)
- Last Synced: 2025-02-26T17:43:31.044Z (3 months ago)
- Language: TypeScript
- Size: 101 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# double-linked-sorted-tree
double linked list + sorted tree | 双向链表 + 排序树## feature | 特性
- keep order for added value | 保持添加的顺序
- log(n) add
- log(n) popMax/popMin## usage | 使用
types
```
interface INode {
parent?: Node;
left?: Node;
right?: Node;
prev: Node;
next: Node;
value: number;
source?: T;
}class DLSTree {
constructor();
add(value: number, source?: T): void;
remove(node: INode): void;
popMin(): INode | undefined;
popMax(): INode | undefined;
iterate(): Generator, void, unknown>;
getHead(): INode | undefined;
getTail(): INode | undefined;
getRoot(): INode | undefined;
size(): number;
updateNodeValue(node: INode, value: number): void;
}
```code example
```
import DLSTree from 'double-linked-sorted-tree'let arr = [100, 1, 11, 30, 10, 4]
let t = new DLSTree()
arr.forEach(x => t.add(x))t.popMax().value // 100
t.popMax().value // 30[...t.iterate()].map(x => x.value) //[1, 11, 10, 4]
```