Created
November 3, 2022 20:50
-
-
Save artalar/3a728f3a8439fb63dc80752e3e376946 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type LLNode<T = any> = { | |
prev: null | LLNode<T> | |
value: T | |
next: null | LLNode<T> | |
} | |
const LLAdd = <T>(prev: LLNode<T>, value: T, next = prev.next) => { | |
prev.next = { prev, value, next } | |
if (next !== null) next.prev = prev.next | |
} | |
const LLDel = ({ prev, next }: LLNode) => { | |
if (prev !== null) prev.next = next | |
if (next !== null) next.prev = prev | |
} | |
const LLFor = <T>(node: null | LLNode<T>, cb: Fn<[T]>) => { | |
while (node !== null) { | |
cb(node.value) | |
node = node.next | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment