Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/lccodder/linkedlist-ts

Default linked list implementation written on TypeScript
https://github.com/lccodder/linkedlist-ts

data-structures linked-list typescript

Last synced: 3 days ago
JSON representation

Default linked list implementation written on TypeScript

Awesome Lists containing this project

README

        

# Static/dynamic typed Linked List realization on TypeScript
### **Simple D/S realization made with TS. Includes only base Linked List methods such as `append`, `prepend`, `to array`, etc**
___
## *Node structure:*
```Typescript
interface ListNode > {
value: TVal,
next: ListNode | null
}
```
* Generic type completion `TVal` extends `any` type w/o `undefined`, `never` and `null` in order to avoid unrealistic value use cases
## `IList` *interface:*
```TypeScript
interface IList {
getHead(): ListNode | null,
getTail(): ListNode | null,
addToTail(dataset: TVal): void,
addToHead(dataset: TVal): void,
toArray(callback?: (array: Array) => void): Array,
replace(oldValue: TVal, newValue: TVal, instancesCount?: number, callback?: (replacedNode: ListNode) => void ): number,
remove(value: TVal, instancesCount?: number, callback?: (removedNode: ListNode) => void ): number
}
```

## **Can be used with fixed type of value or each-node-changing type:**
### Dynamic implementation:
```TypeScript
let ll = new LinkedList.List()
ll.addToTail({prop: "str"})
ll.addToTail(10)
ll.addToHead("string")
```
### Static implementation:
```TypeScript
let ll = new LinkedList.List()
ll.addToTail(1)
ll.addToTail(10)
ll.addToHead(100)
```
---
## Dependencies:
+ `typescript` (save-dev): `^5.2.2`
+ `node`: `v18.17.1`