https://github.com/rfieve/data-structures-converters
A TypeScript library to convert binary-search-trees, doubly linked lists of any types to one another.
https://github.com/rfieve/data-structures-converters
binary-search-tree data-structures doubly-linked-list typescript utility-library
Last synced: about 1 year ago
JSON representation
A TypeScript library to convert binary-search-trees, doubly linked lists of any types to one another.
- Host: GitHub
- URL: https://github.com/rfieve/data-structures-converters
- Owner: rfieve
- License: mit
- Created: 2023-09-22T07:32:36.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-24T10:13:39.000Z (over 1 year ago)
- Last Synced: 2025-03-01T00:48:32.241Z (about 1 year ago)
- Topics: binary-search-tree, data-structures, doubly-linked-list, typescript, utility-library
- Language: TypeScript
- Homepage:
- Size: 302 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 💾🏰♻️ data-structures-converters
A TypeScript library to convert binary-search-trees, doubly linked lists of any types to one another.
## Table of Content
- [💾🏰♻️ data-structures-converters](#️-data-structures-converters)
- [Table of Content](#table-of-content)
- [Installation](#installation)
- [Documentation](#documentation)
- [`convertDLLtoBST`, `convertBSTtoDLLInstance`](#convertdlltobst-convertbsttodllinstance)
- [`convertBSTtoDLL`, `convertDLLtoBSTInstance`](#convertbsttodll-convertdlltobstinstance)
## Installation
```sh
yarn add @romainfieve/data-structures-converters
```
or
```sh
npm install @romainfieve/data-structures-converters
```
## Documentation
### `convertDLLtoBST`, `convertBSTtoDLLInstance`
Converts a doubly linked list to a binary search tree, depending on a given compare function if provided.
```typescript
const compare = (a: number, b: number) => a - b;
const arr = [10, 32, 13, 2, 89, 5, 50];
const list = toDLL(arr, compare);
// Schema of "list"
//
// 2 <-> 5 <-> 10 <-> 13 <-> 32 <-> 50 <-> 89
//
const tree = convertDLLtoBST(list, compare);
// Schema of "tree"
//
// 13
// / \
// 5 50
// / \ / \
// 2 10 32 89
//
```
---
### `convertBSTtoDLL`, `convertDLLtoBSTInstance`
Converts a binary search tree to a doubly linked list, depending on a given compare function if provided.
```typescript
const compare = (a: number, b: number) => a - b;
const arr = [10, 32, 13, 2, 89, 5, 50];
const tree = toBST(list, compare);
// Schema of "tree"
//
// 13
// / \
// 5 50
// / \ / \
// 2 10 32 89
//
const list = convertBSTtoDLL(tree, compare);
// Schema of "list"
//
// 2 <-> 5 <-> 10 <-> 13 <-> 32 <-> 50 <-> 89
//
```
---