A lightweight JavaScript package providing Stack and Queue data structures with TypeScript support.
🛠️ Data Structures | 📚 Stack | 📦 Queue | 💻 JavaScript | ⚙️ TypeScript | 🚀 Algorithms
Note: This package is still under construction for implementing additional data structures such as Graphs, Trees, and more. Stay tuned for updates!
- Implementations of Stack and Queue data structures
- TypeScript support for better type safety
- Simple and intuitive API
- Works with both JavaScript and TypeScript
You can install dstruct-js
via npm:
npm install dstruct-js
import { Stack, Queue } from 'dstruct-js';
// Using Stack
const stack = new Stack();
stack.push(1);
stack.push(2);
console.log(stack.pop()); // 2
console.log(stack.peek()); // 1
// Using Queue
const queue = new Queue();
queue.enqueue(1);
queue.enqueue(2);
console.log(queue.dequeue()); // 1
console.log(queue.peek()); // 2
import { Stack, Queue } from 'dstruct-js';
// Using Stack
const stack = new Stack<number>();
stack.push(1);
stack.push(2);
console.log(stack.pop()); // 2
console.log(stack.peek()); // 1
// Using Queue
const queue = new Queue<number>();
queue.enqueue(1);
queue.enqueue(2);
console.log(queue.dequeue()); // 1
console.log(queue.peek()); // 2
- push(value: T): void - Adds an item to the top of the stack.
- pop(): T | undefined - Removes and returns the top item of the stack.
- peek(): T | undefined - Returns the top item without removing it.
- isEmpty(): boolean - Returns true if the stack is empty.
- enqueue(value: T): void - Adds an item to the end of the queue.
- dequeue(): T | undefined - Removes and returns the item at the - front of the queue.
- peek(): T | undefined - Returns the item at the front without removing it.
- isEmpty(): boolean - Returns true if the queue is empty
To run the tests for this package, you can use:
npm test
To build the package, run:
npm run build
This will compile the TypeScript code into JavaScript and create a dist folder.
This project is licensed under the MIT License. See the LICENSE file for details.
If you’d like to contribute to this project, please fork the repository and submit a pull request. Your contributions are welcome!
- Aniket Pradhan - GitHub Profile