Skip to content

Commit

Permalink
Added documentation for OrderedList.
Browse files Browse the repository at this point in the history
  • Loading branch information
lucianlature committed Apr 27, 2014
1 parent e53f303 commit b987f3e
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 2 deletions.
1 change: 1 addition & 0 deletions examples/linkedlist/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ Linked List
===========

* [Unordered Linked List](https://github.com/lucianlature/data-structures/tree/master/examples/linkedlist/unordered.md)
* [Ordered Linked List](https://github.com/lucianlature/data-structures/tree/master/examples/linkedlist/ordered.md)
130 changes: 130 additions & 0 deletions examples/linkedlist/ordered.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
Ordered Linked List
=====================

Plain JavaScript implementation of an ordered linked list.

------------

###Ordered List###

The list object returned when require is called on this library

var List = require('OrderedList');
var list = new List();

------------

###Methods###

**add(item)**
Adds a new item to the list. It returns nothing.

list.add(3);
list.add(13);
list.add(8);
list.add(5);
list.add(21);

// list has - 3 -> 5 -> 8 -> 13 -> 21

**remove(item)**
Removes the item from the list

list.add(3);
list.add(13);
list.add(8);
list.add(5);
list.add(21);

list.remove(8);

//> list has - 3 -> 5 -> 13 -> 21


**search(item)**
Searches for the item in the list

list.add(3);
list.add(13);
list.add(8);
list.add(5);
list.add(21);

console.log(list.search(3));
//> true
console.log(list.search(4));
//> false


**isEmpty()**
Checks if the list is empty or not

if (!list.isEmpty()) {
while(list.pop());
}
console.log(list.isEmpty());
//> true


**size()**
Returns the number of the items in the list

list.add(3);
list.add(13);
list.add(8);
list.add(5);
list.add(21);

console.log(list.size());
//> 5

if (!list.isEmpty()) {
while(list.pop());
}

console.log(list.size());
//> 0

**indexOf(item)**
Returns the position of item in the list

list.add(3);
list.add(13);
list.add(8);
list.add(5);
list.add(21);

console.log(list.indexOf(8));
//> 2
console.log(list.indexOf(5));
//> 1

**pop()**
Removes and returns the last item in the list.

list.add(3);
list.add(13);
list.add(8);
list.add(5);
list.add(21);

//> list has - 3 -> 5 -> 8 -> 13 -> 21

console.log(list.pop());
//> 21 //list now has - 3 -> 5 -> 8 -> 13


**pop(pos)**
Removes and returns the item at position pos in the list.

list.add(3);
list.add(13);
list.add(8);
list.add(5);
list.add(21);

//> list has - 3 -> 5 -> 8 -> 13 -> 21

console.log(list.pop(1));
//> 5 //list now has - 3 -> 8 -> 13 -> 21

3 changes: 1 addition & 2 deletions examples/linkedlist/unordered.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ Plain JavaScript implementation of an unordered linked list.

------------

###Objects###
###Unordered List###

**Unordered List**
The list object returned when require is called on this library

var List = require('UnorderedList');
Expand Down

0 comments on commit b987f3e

Please sign in to comment.