Skip to content

Commit 42ca6b3

Browse files
committed
Published npm package
1 parent f6edbfe commit 42ca6b3

File tree

7 files changed

+60
-454
lines changed

7 files changed

+60
-454
lines changed

.npmignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules/
2+
coverage/
3+
npm-debug.log
4+
demo/

README.md

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ Data Structures in Javascript
99
# Background
1010
There are neither a lot of resources on internet nor any book which guides and dictates best practices in the implementation of popular Data Structures using Javascript. The purpose of this library is to provide cooked implementation of populare data structures in javascript.
1111

12+
# Installation
13+
npm - `npm install es6-data-structures`
14+
1215
# Getting hands dirty
1316
Clone the repo
1417
`git clone https://github.com/linux-nerd/data-structures.js.git`
@@ -49,60 +52,71 @@ and can be written in -
4952
* typescript
5053

5154
and will be published in
52-
- npm
55+
- ~~npm~~
5356
- bower
5457

5558

5659
# <a name="binary-search-tree"></a>Binary Search Tree
5760
Import BST class and instantiate it
61+
5862
```js
59-
import { BST } from 'data-structures.js/lib/data-structures';
63+
import { BST } from 'es6-data-structures/lib/ds';
6064
const bst = new BST
6165
```
6266

6367
Insert values in binary search Tree
68+
6469
```js
6570
bst.insert(5);
6671
bst.insert(20);
6772
bst.insert(10);
6873
```
74+
6975
Find size of the binary search tree
76+
7077
```js
71-
bst.len() // 3
78+
bst.len // 3
7279
```
7380

7481
Find an item in the binary search tree
82+
7583
```js
7684
bst.lookup(10) // returns an object with keys hasVal, currentNode and parentNode
7785
```
7886

7987
Height of the binary search tree or a node
88+
8089
```js
8190
bst.height() //gives height of the BST 1
8291
bst.height(bst.lookup(10).currentNode) // gives the height of the node - 0
8392
```
8493

8594
Traverse the BST and return a List
95+
8696
```js
8797
bst.traverse('inOrder') // traverse method expects a parameter - inOrder|preOrder|postOrder| levelOrder
8898
```
99+
89100
Delete elements from binary search tree
101+
90102
```js
91103
bst.delete(10);
92104
bst.delete(20);
93105
```
94106

95107
# <a name="graph"></a> Graph
96108
Import Graph class and instantiate it and create an object of adjacency list implementation of Graph. To create a directed graph pass the string argument '**directed**'. If the Graph class is called without a parameter then by default its undirected graph.
109+
97110
```js
98-
import { Graph } from 'data-structures.js/lib/data-structures';
111+
import { Graph } from 'es6-data-structures/lib/ds';
99112
const graph = new Graph; // this will create an undirected Graph
100113
const graph = new Graph('directed'); // this will create a directed graph or diGraph
101114

102115
const adjList = graph.createGraph('adjList'); // create Adjacency List implementation of graph
103116
```
104117

105118
Add and remove a node to the graph
119+
106120
```js
107121
// add a node
108122
adjList.addNode('A');
@@ -114,6 +128,7 @@ adjList.removeNode('B');
114128
```
115129

116130
Add and remove an edge between two nodes to the graph. iF a node is not added, then it first adds the node and then create an edge.
131+
117132
```js
118133
// add an edge
119134
adjList.addEdge('A', 'B', 200); // it will add an edge between A and B of weight 200
@@ -125,11 +140,13 @@ adjList.removeEdge('B', 'C');
125140
```
126141

127142
Find size of the graph.
143+
128144
```js
129145
adjList.size // 3
130146
```
131147

132148
Find weight of the edge in weighted graph
149+
133150
```js
134151
adjList.getEdgeWeight('A', 'B');
135152
```
@@ -139,11 +156,12 @@ adjList.getEdgeWeight('A', 'B');
139156
Import Queue class and create a queue object.
140157

141158
```js
142-
import { Queue } from 'data-structures.js/lib/data-structures';
159+
import { Queue } from 'es6-data-structures/lib/ds';
143160
const queue = new Queue;
144161
```
145162

146163
Add and remove elements to and from the created queue respectively
164+
147165
```js
148166
// add elements to the queue
149167
queue.enqueue('A');
@@ -155,12 +173,14 @@ queue.dequeue();
155173
```
156174

157175
Get size and top element in the queue
176+
158177
```js
159178
queue.size() // 2
160179
queue.top() // A
161180
```
162181

163182
Clear the entire queue at once
183+
164184
```js
165185
queue.clear() // this will empty the queue
166186
```

0 commit comments

Comments
 (0)