
This is a standalone Linked List data structure from the data-structure-typed collection. If you wish to access more
data structures or advanced features, you can transition to directly installing the
complete data-structure-typed package
npm i linked-list-typed --save
yarn add linked-list-typed
const browserHistory = new DoublyLinkedList<string>();
browserHistory.push('home page');
browserHistory.push('search page');
browserHistory.push('details page');
console.log(browserHistory.last); // 'details page';
console.log(browserHistory.pop()); // 'details page';
console.log(browserHistory.last); // 'search page';
interface CacheEntry {
key: string;
value: string;
}
// Simulate LRU cache using DoublyLinkedList
// DoublyLinkedList is perfect because:
// - O(1) delete from any position
// - O(1) push to end
// - Bidirectional traversal for LRU policy
const cacheList = new DoublyLinkedList<CacheEntry>();
const maxSize = 3;
// Add cache entries
cacheList.push({ key: 'user:1', value: 'Alice' });
cacheList.push({ key: 'user:2', value: 'Bob' });
cacheList.push({ key: 'user:3', value: 'Charlie' });
// Try to add a new entry when cache is full
if (cacheList.length >= maxSize) {
// Remove the oldest (first) entry
const evicted = cacheList.shift();
console.log(evicted?.key); // 'user:1';
}
// Add new entry
cacheList.push({ key: 'user:4', value: 'Diana' });
// Verify current cache state
console.log(cacheList.length); // 3;
const cachedKeys = [...cacheList].map(entry => entry.key);
console.log(cachedKeys); // ['user:2', 'user:3', 'user:4'];
// Access entry (in real LRU, this would move it to end)
const foundEntry = [...cacheList].find(entry => entry.key === 'user:2');
console.log(foundEntry?.value); // 'Bob';
const list = new DoublyLinkedList<number>([5, 10, 15, 20]);
console.log(list.find(n => n >= 12)); // 15;
const list = new DoublyLinkedList<number>([1, 2, 3]);
const sum: number[] = [];
list.forEach(n => sum.push(n));
console.log(sum); // [1, 2, 3];
API Docs
Live Examples
Examples Repository
| Data Structure Typed |
C++ STL |
java.util |
Python collections |
| DoublyLinkedList<E> |
list<T> |
LinkedList<E> |
- |
| SinglyLinkedList<E> |
- |
- |
- |
doubly-linked-list
| test name | time taken (ms) | executions per sec | sample deviation |
|---|
| 1,000,000 push | 221.57 | 4.51 | 0.03 |
| 1,000,000 unshift | 229.02 | 4.37 | 0.07 |
| 1,000,000 unshift & shift | 169.21 | 5.91 | 0.02 |
| 1,000,000 insertBefore | 314.48 | 3.18 | 0.07 |
singly-linked-list
| test name | time taken (ms) | executions per sec | sample deviation |
|---|
| 10,000 push & pop | 212.98 | 4.70 | 0.01 |
| 10,000 insertBefore | 250.68 | 3.99 | 0.01 |
| Algorithm |
Function Description |
Iteration Type |
| Principle |
Description |
| Practicality |
Follows ES6 and ESNext standards, offering unified and considerate optional parameters, and simplifies method names. |
| Extensibility |
Adheres to OOP (Object-Oriented Programming) principles, allowing inheritance for all data structures. |
| Modularization |
Includes data structure modularization and independent NPM packages. |
| Efficiency |
All methods provide time and space complexity, comparable to native JS performance. |
| Maintainability |
Follows open-source community development standards, complete documentation, continuous integration, and adheres to TDD (Test-Driven Development) patterns. |
| Testability |
Automated and customized unit testing, performance testing, and integration testing. |
| Portability |
Plans for porting to Java, Python, and C++, currently achieved to 80%. |
| Reusability |
Fully decoupled, minimized side effects, and adheres to OOP. |
| Security |
Carefully designed security for member variables and methods. Read-write separation. Data structure software does not need to consider other security aspects. |
| Scalability |
Data structure software does not involve load issues. |