0.2.2 • Published 7 months ago
data-structures-simple v0.2.2
Data Structures Simple
Installation and Usage
npm
npm i data-structures-simple
yarn
yarn add data-structures-simple
bun
bun add data-structures-simple
Usage
import { LinkedList } from "data-structures-simple";
const list = new LinkedList();
list.addLast(1);
list.addLast(2);
list.addLast(3);
list.addLast(4);
console.log(list.toArray()); // [1, 2, 3, 4]
list.removeLast();
console.log(list.indexOf(4)); // -1
Documentation
LinkedList
Properties
Property Name | Description | Type |
---|---|---|
Node | The node class | class |
Methods
Method Name | Description | Return Value |
---|---|---|
addLast | Adds an element at the end of the list | void |
addFirst | Adds an element at the beginning of the list | void |
addAt | Adds an element at the specified index | void |
removeFirst | Removes the first element from the list | void |
removeLast | Removes the last element from the list | void |
remove | Removes the first occurrence of the specified element from the list | void |
reverse | Reverses the order of the elements in the list | void |
removeAt | Removes the element at the specified index | void |
indexOf | Returns the index of the first occurrence of the specified element in list. | number (-1 if not found) |
contains | Returns true if the list contains the specified element | boolean |
getSize | Returns the number of elements in the list | number |
isEmpty | Returns true if the list is empty | boolean |
toArray | Returns an array containing all of the elements in this list | array |
getNode | Returns the node at the specified index | Node |
Stack
import { Stack, DynamicStack } from "data-structures-simple";
// Stack (default) size = 10
// DynamicStack has no size limit
Properties
Property Name | Description | Type |
---|---|---|
Stack | class |
Methods
Method Name | Description | Return Value |
---|---|---|
push | Insert a new element into the stack. | void |
pop | Removes and returns the top element from the stack. | item (T) |
peek | Returns the top element from the stack without removing it. | item (T) |
isEmpty | Returns true if the stack is empty, false otherwise. | boolean |
toArray | Returns the stack as an array. | array (T[]) |
size | Returns the number of elements in the stack. | number |
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
License
Author
Acknowledgments
Contact
Project Status
- LinkedList
- Stack
- Queue
- HashTable
- Heap
- Graph
- Tree
- Trie
- Binary Search Tree
Project Statistics