-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflood_fill.cpp
More file actions
65 lines (39 loc) · 1.08 KB
/
Copy pathflood_fill.cpp
File metadata and controls
65 lines (39 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include"essentials.cpp"
#define N 8
void flood_fill(int matrix[N][N],int x,int y,int old,int new_colour){
if(x<0 || x>=N || y<0 || y>=N){
return;
}
if(matrix[x][y]==old){
matrix[x][y]=new_colour;
}
else{
return;
}
flood_fill(matrix,x+1,y,old,new_colour);
flood_fill(matrix,x-1,y,old,new_colour);
flood_fill(matrix,x,y+1,old,new_colour);
flood_fill(matrix,x,y-1,old,new_colour);
}
int main(){
int matrix[N][N]={{1, 1, 1, 1, 1, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 0, 0},
{1, 0, 0, 1, 1, 0, 1, 1},
{1, 2, 2, 2, 2, 0, 1, 0},
{1, 1, 1, 2, 2, 0, 1, 0},
{1, 1, 1, 2, 2, 2, 2, 0},
{1, 1, 1, 1, 1, 2, 1, 1},
{1, 1, 1, 1, 1, 2, 2, 1},};
int x=4;
int y=4;
int old_color=2;
int new_color=3;
flood_fill(matrix,x,y,old_color,new_color);
for(int i=0;i<N;i++){
for(int j=0;j<N;j++){
cout<<matrix[i][j]<<" ";
}
cout<<endl;
}
return 1;
}