Skip to content

Instantly share code, notes, and snippets.

@artalar
Created November 3, 2022 20:50
Show Gist options
  • Save artalar/3a728f3a8439fb63dc80752e3e376946 to your computer and use it in GitHub Desktop.
Save artalar/3a728f3a8439fb63dc80752e3e376946 to your computer and use it in GitHub Desktop.
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