Struts is a simple library for data structures in JavaScript (NodeJS). It has been created as part of my studies about this subject and as a way to fill my needs of coding.
For now you should manually download Struts from this repository and save it on your dependency folder.
In your code, you can just require it:
const struts = require('./path/struts.js');
Here you will find the documentation for this library.
A simple implementation of a list.
struts.list.initEmpty(size)
Param | Type | Explanation | Return |
---|---|---|---|
size | Integer | Defines the length of an empty list | Boolean |
struts.list.size()
Param | Type | Explanation | Return |
---|---|---|---|
- | - | Return the current size from the list | Integer |
struts.list.moveBeginning()
Param | Type | Explanation | Return |
---|---|---|---|
- | - | Set the "pointer" position to the beginning of the list | Integer [a pointer's value] |
struts.list.moveEnd()
Param | Type | Explanation | Return |
---|---|---|---|
- | - | Set the "pointer" position to the end of the list | Integer [a pointer's value] |
struts.list.forward()
Param | Type | Explanation | Return |
---|---|---|---|
- | - | Increments the current postion by one step | - |
struts.list.backward()
Param | Type | Explanation | Return |
---|---|---|---|
- | - | Decrements the current position by one step | - |
struts.list.append(element)
Param | Type | Explanation | Return |
---|---|---|---|
Element | - | Insert an element at the end of the list | Boolean |
struts.list.insertBeginning(element)
Param | Type | Explanation | Return |
---|---|---|---|
Element | - | Insert an element at the beginning of the list | Bolean |
struts.list.insert(index, element)
Param | Type | Explanation | Return |
---|---|---|---|
Index, Element | - | Insert an element at the provided position | Bolean |
struts.list.pullOut()
Param | Type | Explanation | Return |
---|---|---|---|
- | - | Returns and removes the last element on the list | Element |
struts.list.removeElement(element)
Param | Type | Explanation | Return |
---|---|---|---|
Element | - | Returns the removed element | Element |
struts.list.returnList()
Param | Type | Explanation | Return |
---|---|---|---|
- | - | Returns this list | Array |
struts.list.returnCurrentElement()
Param | Type | Explanation | Return |
---|---|---|---|
- | - | Returns the current element which the position points to | Element |
struts.list.erase()
Param | Type | Explanation | Return |
---|---|---|---|
- | - | Erases the list and set position to zero | Boolean |
struts.list.logList()
Param | Type | Explanation | Return |
---|---|---|---|
- | - | Prints the list itens | - |
struts.list.logCurrentElement()
Param | Type | Explanation | Return |
---|---|---|---|
- | - | Prints the element where the position points to | - |
struts.list.logCurrentPos()
Param | Type | Explanation | Return |
---|---|---|---|
- | - | Prints the current position | - |
A Stack is one of the most important data structures in informatics, some of the most basic problems can be solved using it.
struts.stack.returnStack()
Param | Type | Explanation | Return |
---|---|---|---|
- | - | Return the stack | Array |
struts.stack.insert(element)
Param | Type | Explanation | Return |
---|---|---|---|
Element | - | Insert an element on the Stack | Boolean |
struts.stack.size()
Param | Type | Explanation | Return |
---|---|---|---|
- | - | Returns the stack's size | Integer |
struts.stack.pullOut()
Param | Type | Explanation | Return |
---|---|---|---|
- | - | Returns an removes an element of the stack | Element |
struts.stack.peek()
Param | Type | Explanation | Return |
---|---|---|---|
- | - | Returns an element of the stack but doesn't removes it | Element |
struts.stack.erase()
Param | Type | Explanation | Return |
---|---|---|---|
- | - | Erases all the stack's content | Boolean |
struts.stack.look()
Param | Type | Explanation | Return |
---|---|---|---|
- | - | Prints the current stack | - |
struts.stack.exchange()
Param | Type | Explanation | Return |
---|---|---|---|
- | - | Changes the position of newest stacked element with the second newest | Boolean |
struts.stack.duplicate()
Param | Type | Explanation | Return |
---|---|---|---|
- | - | Makes a copy of the newest element and put it on the stack | Boolean |
struts.stack.revert()
Param | Type | Explanation | Return |
---|---|---|---|
- | - | Reverts the stack orientation and returns it | Array |
A queue is an good way of structuring actions with a logical order in time.
struts.queue.returnQueue()
Param | Type | Explanation | Return |
---|---|---|---|
- | - | Returns the queue | Array |
struts.queue.enqueue(element)
Param | Type | Explanation | Return |
---|---|---|---|
Element | - | Insert an element in the end of the queue | Boolean |
struts.queue.dequeue()
Param | Type | Explanation | Return |
---|---|---|---|
- | - | Returns and remove the first element of the queue | Element |
struts.queue.peek()
Param | Type | Explanation | Return |
---|---|---|---|
- | - | Returns the first element of the queue but do not removes it | Element |
struts.queue.revert()
Param | Type | Explanation | Return |
---|---|---|---|
- | - | Reverts the queue's orientation | Boolean |
struts.queue.logQueue()
Param | Type | Explanation | Return |
---|---|---|---|
- | - | Prints the whole queue | - |
A Singly Linked List is a data structure in a list form, where each node of a list holds a value and a pointer¹ to the next node of the list.
¹ As in Javascript we cannot work with real pointers, this implementation simulates this behave with embedded objects.
struts.sLinkedList.newList(element)
Param | Type | Explanation | Return |
---|---|---|---|
element | - | This method takes the first element for the list and creates it | Object |
struts.sLinkedList.insert(element)
Param | Type | Explanation | Return |
---|---|---|---|
element | - | This method inserts an element in the list | Boolean |