Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 719e150

Browse files
committed
Refactoring of the graph algorithms
1 parent 89879a6 commit 719e150

File tree

8 files changed

+12
-507
lines changed

8 files changed

+12
-507
lines changed

src/data-structures/heap.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function Heap(cmp) {
1313
return a - b;
1414
};
1515
}
16-
}
16+
};
1717

1818
/**
1919
* Exchange indexes with start index given as argument
@@ -41,8 +41,7 @@ Heap.prototype._heapify = function (index) {
4141
this._heap[extr] = temp;
4242
this._heapify(extr);
4343
}
44-
45-
}
44+
};
4645

4746
/**
4847
* Changes the key for give index. Complexity O(log n).
@@ -66,7 +65,7 @@ Heap.prototype.changeKey = function (index, value) {
6665
}
6766
}
6867
return parent;
69-
}
68+
};
7069

7170
/**
7271
* Adds new element to the heap. Complexity O(log n).
@@ -78,7 +77,7 @@ Heap.prototype.changeKey = function (index, value) {
7877
Heap.prototype.add = function (value) {
7978
this._heap.push(value);
8079
return this.changeKey(this._heap.length - 1, value);
81-
}
80+
};
8281

8382
/**
8483
* Gets the current value which is on the top of the heap. Complexity O(1).
@@ -88,7 +87,7 @@ Heap.prototype.add = function (value) {
8887
*/
8988
Heap.prototype.top = function () {
9089
return this._heap[0];
91-
}
90+
};
9291

9392
/**
9493
* Removes and returns the current extremum value which is on the top of the heap.
@@ -104,6 +103,10 @@ Heap.prototype.extract = function () {
104103
var extr = this._heap.shift();
105104
this._heapify(0);
106105
return extr;
107-
}
106+
};
107+
108+
Heap.prototype.isEmpty = function () {
109+
return !this._heapify.length;
110+
};
108111

109112
exports.Heap = Heap;

src/graphs/bfs.js

Lines changed: 0 additions & 68 deletions
This file was deleted.

src/graphs/dfs.js

Lines changed: 0 additions & 73 deletions
This file was deleted.

src/graphs/dijkstra.js

Lines changed: 0 additions & 112 deletions
This file was deleted.

src/graphs/floyd.js

Lines changed: 0 additions & 74 deletions
This file was deleted.

0 commit comments

Comments
 (0)