We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 36e74ba commit db9a825Copy full SHA for db9a825
4 files changed
algorithm/category.json
@@ -57,6 +57,7 @@
57
"etc": {
58
"name": "Uncategorized",
59
"list": {
60
+ "flood_fill": "Flood Fill"
61
}
62
63
algorithm/etc/flood_fill/desc.json
@@ -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
+}
algorithm/etc/flood_fill/flood_fill/code.js
@@ -0,0 +1,23 @@
+function FloodFill(i, j, oldColor, newColor) {
+
+ if (i < 0 || i >= G.length || j < 0 || j >= G[i].length) return;
+ if (G[i][j] != oldColor) return;
+ // set the color of node to newColor
+ G[i][j] = newColor;
+ 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
+ tracer._denotify(i, j);
19
+ tracer._deselect(i, j)._wait();
20
21
22
+FloodFill(4, 4, '-', 'a');
23
algorithm/etc/flood_fill/flood_fill/data.js
@@ -0,0 +1,13 @@
+var tracer = new Array2DTracer ();
+var G = [
+ ['#', '#', '#', '#', '#', '#', '#', '#', '#'],
+ ['#', '-', '-', '-', '#', '-', '-', '-', '#'],
+ ['#', '-', '-', '#', '-', '-', '-', '-', '#'],
+ ['#', '#', '#', '-', '-', '-', '#', '#', '#'],
+ ['#', '-', '-', '-', '-', '#', '-', '-', '#'],
+ ['#', '#', '#', '#', '#', '#', '#', '#', '#']
+];
+tracer._setData(G);
0 commit comments