Skip to content

Commit c503a35

Browse files
author
duaraghav8@gmail
committed
Merge remote-tracking branch 'upstream/gh-pages'
2 parents f6d7864 + c175da7 commit c503a35

File tree

5 files changed

+45
-2
lines changed

5 files changed

+45
-2
lines changed

algorithm/category.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"etc": {
5959
"name": "Uncategorized",
6060
"list": {
61+
"flood_fill": "Flood Fill"
6162
}
6263
}
6364
}

algorithm/etc/flood_fill/desc.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Flood Fill": "Flood fill, also called seed fill, is an algorithm that determines the area connected to a given node in a multi-dimensional array",
3+
"References": [
4+
"<a href='https://en.wikipedia.org/wiki/Flood_fill'>Wikipedia</a>"
5+
],
6+
"files": {
7+
"flood_fill": ""
8+
}
9+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
function FloodFill(i, j, oldColor, newColor) {
2+
3+
if (i < 0 || i >= G.length || j < 0 || j >= G[i].length) return;
4+
if (G[i][j] != oldColor) return;
5+
6+
// set the color of node to newColor
7+
G[i][j] = newColor;
8+
9+
tracer._select(i, j)._wait();
10+
tracer._notify(i, j, G[i][j])._wait();
11+
12+
// next step four-way
13+
FloodFill(i + 1, j, oldColor, newColor);
14+
FloodFill(i - 1, j, oldColor, newColor);
15+
FloodFill(i, j + 1, oldColor, newColor);
16+
FloodFill(i, j - 1, oldColor, newColor);
17+
}
18+
19+
FloodFill(4, 4, '-', 'a');
20+
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
var tracer = new Array2DTracer ();
2+
var G = [
3+
['#', '#', '#', '#', '#', '#', '#', '#', '#'],
4+
['#', '-', '-', '-', '#', '-', '-', '-', '#'],
5+
['#', '-', '-', '-', '#', '-', '-', '-', '#'],
6+
['#', '-', '-', '#', '-', '-', '-', '-', '#'],
7+
['#', '#', '#', '-', '-', '-', '#', '#', '#'],
8+
['#', '-', '-', '-', '-', '#', '-', '-', '#'],
9+
['#', '-', '-', '-', '#', '-', '-', '-', '#'],
10+
['#', '-', '-', '-', '#', '-', '-', '-', '#'],
11+
['#', '#', '#', '#', '#', '#', '#', '#', '#']
12+
];
13+
tracer._setData(G);

js/script.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,11 @@ $.getJSON('./algorithm/category.json', function (data) {
241241
for (var category in list) {
242242
(function (category) {
243243
var $category = $('<button class="category">')
244-
.append('<i class="fa fa-fw fa-caret-down">')
244+
.append('<i class="fa fa-fw fa-caret-right">')
245245
.append(list[category].name);
246246
$category.click(function () {
247247
$('[data-category="' + category + '"]').toggleClass('collapse');
248-
$(this).find('i.fa').toggleClass('fa-caret-down fa-caret-right');
248+
$(this).find('i.fa').toggleClass('fa-caret-right fa-caret-down');
249249
});
250250
$('#list').append($category);
251251
var subList = list[category].list;

0 commit comments

Comments
 (0)