EstruturasDeDados
Some Data Structs implementations in Javascript for browsers or node.js
Data Structs implementated
- List
- Stack
- Binary Search Tree
- Queue
- Map
Instalation
There are 2 ways for install EstruturasDeDados:
- In browsers
- In Node.js
If you need in browsers:
- Download and copy the file "src/estruturas.js" to your path folder
- Then put in your HTML file <script src='path/to/estruturas.js'></script>
If you need in Node:
- $ npm install estruturasdedados
- var ESTRUTURAS = require('estruturasdedados')
Then let the magic begin
Exemples
List:
//Here you create a instance of Listvar lista = ; //If you want to insert a capacity, you can do thatvar lista = 10; //Here you just add a item in listlista; //Or if you want, you can pass the index that you will input with the method "setItem"lista; //You can get some itensvar obj = lista; //If you want add an array with some objectslista; //You can insert an item at the specified index like thatlista; //Then, if you want clear the Listlistaclear; //If you need search an itemvar index = lista; //Checking if item existsvar flag = lista; //You can execute a function in all elementslista; //Then you can remove one item at specified indexlista; //Or remove a rangelista; //You also can get a subList with methodvar mySubList = lista;
Binary Search Tree:
//Here you create a instance of Binary Search Treevar tree = ; //Creating one node of your Binary Search Treevar no = ESTRUTURASArvoreBinariaBusca; //Our node have home method, but you only need "setValue" and "getValue"no;var value = no; //If you want put your no into the tree you need thistree; //Then you can search for some value in your tree like that. It may return one "No" object, if the value wasn't in tree, it will return falsevar noS = tree;
Stack(FIFO strategy) and Queue(LIFO strategy):
//First you should create an instance of your Struct. We will use Queue in other exemplesvar struct = ; //for Stackvar struct = ; //for Queue //Then, you may add itensstruct; //You can get some objects following the strategy of the structvar obj = struct; //You also can clear you structstructclear; //Or check if is emptystruct; //Or check the size structsize;
Map:
//Creating an instance of your Mapvar map = ; //Adding an item on mapmap; //You can remove an item with a keymap; //Or get an itemvar item = map; //Then you can clearmapclear;