Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ianseabrook/javascript-datastructures-algorithms
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: second-edition
Choose a base ref
...
head repository: loiane/javascript-datastructures-algorithms
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: second-edition
Choose a head ref
Able to merge. These branches can be automatically merged.
  • 12 commits
  • 9 files changed
  • 3 contributors

Commits on Aug 25, 2016

  1. Copy the full SHA
    d0ebbf9 View commit details

Commits on Sep 1, 2016

  1. closes loiane#13

    loiane authored Sep 1, 2016
    Copy the full SHA
    7868536 View commit details

Commits on Sep 11, 2016

  1. Update 05-CircularLinkedList2.js

    fix some errors
    beizhedenglong authored Sep 11, 2016
    Copy the full SHA
    2a89e21 View commit details
  2. Merge pull request loiane#17 from beizhedenglong/patch-1

    Update 05-CircularLinkedList2.js
    loiane authored Sep 11, 2016
    Copy the full SHA
    a641eb2 View commit details
  3. fix bug in CircularLinkedList

    There is a bug in insert function. If you insert an element in an empty
    list at the first  position. It will throw a TypeError: Cannot read
    property 'next' of null.
    beizhedenglong committed Sep 11, 2016
    Copy the full SHA
    94b2c68 View commit details

Commits on Nov 2, 2016

  1. Fix aValues being undefined

    terryx committed Nov 2, 2016
    Copy the full SHA
    c2eb4ac View commit details
  2. Merge pull request loiane#19 from terryx/second-edition

    Fix aValues being undefined
    loiane authored Nov 2, 2016
    Copy the full SHA
    9ff3095 View commit details
  3. Merge pull request loiane#18 from beizhedenglong/second-edition

    fix bug in CircularLinkedList
    loiane authored Nov 2, 2016
    Copy the full SHA
    d287512 View commit details

Commits on Apr 17, 2017

  1. Update README.md

    loiane authored Apr 17, 2017
    Copy the full SHA
    a5fc23e View commit details

Commits on Aug 21, 2017

  1. fixes loiane#23

    loiane committed Aug 21, 2017
    Copy the full SHA
    c44e749 View commit details

Commits on Sep 7, 2017

  1. gitignore

    loiane committed Sep 7, 2017
    Copy the full SHA
    10b24fd View commit details

Commits on Nov 20, 2017

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    f065676 View commit details
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.idea/*
*.log
*.log
node_modules
coverage
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ Source code of **Learning JavaScript Data Structures and Algorithms** book.

| 1st edition | 2nd edition |
| ------------- |:-------------:|
| ![1st edition](https://d1ldz4te4covpm.cloudfront.net/sites/default/files/imagecache/ppv4_main_book_cover/4874OS_Learning%20JavaScript%20Data%20Structures%20and%20Algorithms.jpg) | ![2nd edition](https://dz13w8afd47il.cloudfront.net/sites/default/files/imagecache/ppv4_main_book_cover/B05348_MockupCover_Normal.jpg) |
| ![1st edition](https://d1ldz4te4covpm.cloudfront.net/sites/default/files/imagecache/ppv4_main_book_cover/4874OS_Learning%20JavaScript%20Data%20Structures%20and%20Algorithms.jpg) | ![2nd edition](https://d255esdrn735hr.cloudfront.net/sites/default/files/imagecache/ppv4_main_book_cover/5493OS_5348_Learning%20JavaScript%20Data%20Structures%20and%20Algorithms,%20Second%20Edition.jpg) |
| [Book link](http://amzn.to/1Y1OWPx)| [Book link](http://amzn.to/1TSkcA1)|

Book link - first edition:
@@ -17,6 +17,7 @@ Book link - first edition:
Book link - second edition:
- [Packt](https://www.packtpub.com/web-development/learning-javascript-data-structures-and-algorithms-second-edition)
- [Amazon](http://amzn.to/1TSkcA1)
- [Brazilian Portuguese version](https://novatec.com.br/livros/estruturas-de-dados-algoritmos-em-javascript/)

### List of Chapters:

2 changes: 1 addition & 1 deletion chapter01/14-ES6ParameterHandling.js
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ function sum2 (x, y, z) {
z = 3;
return x + y + z;
};
console.log(sum2(4,2)); //outpus 10
console.log(sum2(4,2)); //outpus 9

//******* EcmaScript 6: spread operator ('...')
var params = [3, 4, 5];
2 changes: 1 addition & 1 deletion chapter02/06-ES6Methods.js
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@ console.log(aKeys.next()); // {value: 1, done: false }
console.log(aKeys.next()); // {value: 2, done: false }

console.log('Array.values');
//let aValues = numbers.values();
let aValues = numbers.values();
console.log(aValues.next()); // {value: 1, done: false } done false means iterator has more values
console.log(aValues.next()); // {value: 2, done: false }
console.log(aValues.next()); // {value: 3, done: false }
27 changes: 17 additions & 10 deletions chapter05/05-CircularLinkedList.js
Original file line number Diff line number Diff line change
@@ -46,16 +46,22 @@ function CircularLinkedList() {
index = 0;

if (position === 0){ //add on first position

node.next = current;

//update last element
while(current.next !== head){ //last element will be head instead of NULL
current = current.next;

if(!head){ // if no node in list
head = node;
node.next = head;
}else{
node.next = current;

//update last element
while(current.next !== head){ //last element will be head instead of NULL
current = current.next;
}

head = node;
current.next = head;
}

head = node;
current.next = head;


} else {
while (index++ < position){
@@ -180,4 +186,5 @@ function CircularLinkedList() {
this.print = function(){
console.log(this.toString());
};
}
}

27 changes: 15 additions & 12 deletions chapter05/05-CircularLinkedList2.js
Original file line number Diff line number Diff line change
@@ -58,15 +58,18 @@ let CircularLinkedList2 = (function () {

if (position === 0) { //add on first position

node.next = current;

//update last element
while (current.next !== this.getHead()) { //last element will be head instead of NULL
current = current.next;
}

head.set(this, node);
current.next = this.getHead();
if(!this.getHead()) { // if no node in list
head.set(this, node);
node.next = this.getHead();
} else {
node.next = current;
//update last element
while(current.next !== this.getHead()) { //last element will be head instead of NULL
current = current.next;
}
head.set(this, node);
current.next = this.getHead();
}

} else {
while (index++ < position) {
@@ -133,8 +136,8 @@ let CircularLinkedList2 = (function () {

remove(element) {

let index = indexOf(element);
return removeAt(index);
let index = this.indexOf(element);
return this.removeAt(index);
}

indexOf(element) {
@@ -198,4 +201,4 @@ let CircularLinkedList2 = (function () {
}
}
return CircularLinkedList2;
})();
})();
15 changes: 12 additions & 3 deletions chapter07/07-HashCollisionLinearProbing.js
Original file line number Diff line number Diff line change
@@ -46,13 +46,22 @@ function HashLinearProbing(){
return table[position].value;
} else {
var index = ++position;
while (table[index] === undefined || table[index].key !== key){
while (table[index] !== undefined && (table[index] && table[index].key !== key)){
index++;
}
if (table[index].key === key) {
if (table[index] && table[index].key === key) {
return table[index].value;
}
}
} else { //search for possible deleted value
var index = ++position;
while (table[index] == undefined || index == table.length ||
(table[index] !== undefined && table[index] && table[index].key !== key)){
index++;
}
if (table[index] && table[index].key === key) {
return table[index].value;
}
}
return undefined;
};
@@ -82,4 +91,4 @@ function HashLinearProbing(){
}
}
};
}
}
8 changes: 8 additions & 0 deletions chapter07/08-UsingHashCollisionLinearProbing.js
Original file line number Diff line number Diff line change
@@ -26,4 +26,12 @@ console.log('**** Remove **** ');

hashLinearProbing.remove('Gandalf');
console.log(hashLinearProbing.get('Gandalf'));
hashLinearProbing.print();

console.log('**** Remove Test 2 **** ');
console.log('Removing Jonathan', hashLinearProbing.remove('Jonathan'));
console.log('**** Print **** ');
hashLinearProbing.print();
console.log('Get Jamie', hashLinearProbing.get('Jamie'));
console.log('**** Print **** ');
hashLinearProbing.print();
4 changes: 0 additions & 4 deletions chapter08/02-UsingBinarySearchTree.js
Original file line number Diff line number Diff line change
@@ -50,7 +50,3 @@ tree.inOrderTraverse(printNode);

console.log('********* raw data structure ***********');
console.log(tree.getRoot());

console.log('********* printing HTML tree ***********');
var parent = document.getElementsByTagName('body')[0];
printHTMLTree(tree.getRoot(), parent, 255);