Skip to content

Commit d864edf

Browse files
committed
Added docs for Linked List
1 parent f266ebe commit d864edf

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ Data structures covered so far -
4545
- [Binary Search Tree](#binary-search-tree)
4646
- [Graph](#graph)
4747
- [Queue](#queue)
48+
- [Linked List](#link-list)
4849

4950
# Contribution
5051
Your contribution is highly appreciated. You can contribute in several ways -
@@ -196,3 +197,48 @@ Clear the entire queue at once
196197
```js
197198
queue.clear() // this will empty the queue
198199
```
200+
201+
# <a name="link-list"></a> Linked List
202+
203+
Import LinkedList data structure and create a list object.
204+
205+
```js
206+
import { LinkedList } from 'es6-data-structures/lib/ds';
207+
const list = new LinkedList;
208+
```
209+
210+
Insert and Remove Items from the list
211+
212+
```js
213+
// inserts item at the end of the list
214+
list.insert('firstVal');
215+
list.insert('SecondVal');
216+
217+
list.insertAfter('Mid', 'firstVal'); // insert Mid after firstVal
218+
list.insertBefore('xyz', 'secondVal'); // insert xyz before secondVal
219+
220+
list.remove('firstVal') // removes firstVal from the list.
221+
```
222+
223+
Get size and search for an item and check if the list is empty
224+
225+
```js
226+
list.size() // 3
227+
list.search('xyz') // true
228+
list.search('abc') // false
229+
list.isEmpty() // false
230+
```
231+
232+
Iterate over list using for...of loop
233+
234+
```js
235+
for(const item of list) {
236+
console.log(item) // 'firstVal', 'Mid', 'xyz', 'secondVal'
237+
}
238+
```
239+
240+
Usage as spread operator
241+
242+
```js
243+
const items = [...list] // ['firstVal', 'Mid', 'xyz', 'secondVal']
244+
```

0 commit comments

Comments
 (0)