You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+152-7Lines changed: 152 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,25 +9,42 @@ Data Structures in Javascript
9
9
# Background
10
10
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.
Your contribution is highly appreciated. You can contribute in several ways -
@@ -47,7 +64,135 @@ and can be written in -
47
64
* typescript
48
65
49
66
and will be published in
50
-
- npm
67
+
-~~npm~~
51
68
- bower
52
69
53
70
71
+
# <aname="binary-search-tree"></a>Binary Search Tree
72
+
Import BST class and instantiate it
73
+
74
+
```js
75
+
import { BST } from'es6-data-structures/lib/ds';
76
+
constbst=newBST
77
+
```
78
+
79
+
Insert values in binary search Tree
80
+
81
+
```js
82
+
bst.insert(5);
83
+
bst.insert(20);
84
+
bst.insert(10);
85
+
```
86
+
87
+
Find size of the binary search tree
88
+
89
+
```js
90
+
bst.len// 3
91
+
```
92
+
93
+
Find an item in the binary search tree
94
+
95
+
```js
96
+
bst.lookup(10) // returns an object with keys hasVal, currentNode and parentNode
97
+
```
98
+
99
+
Height of the binary search tree or a node
100
+
101
+
```js
102
+
bst.height() //gives height of the BST 1
103
+
bst.height(bst.lookup(10).currentNode) // gives the height of the node - 0
104
+
```
105
+
106
+
Traverse the BST and return a List
107
+
108
+
```js
109
+
bst.traverse('inOrder') // traverse method expects a parameter - inOrder|preOrder|postOrder| levelOrder
110
+
```
111
+
112
+
Delete elements from binary search tree
113
+
114
+
```js
115
+
bst.delete(10);
116
+
bst.delete(20);
117
+
```
118
+
119
+
# <aname="graph"></a> Graph
120
+
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.
0 commit comments