-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlood_Fill_v.cpp
More file actions
37 lines (37 loc) · 1.01 KB
/
Flood_Fill_v.cpp
File metadata and controls
37 lines (37 loc) · 1.01 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
#include<bits/stdc++.h>
#include<bits/stdc++.h>
#define vi vector<int>
using namespace std;
void prm(vector<vi>& matrix)
{
for(auto x:matrix){
for(auto y:x){
cout<<y<<" ";
}cout<<"\n";
}
}
void rec_func(vector<vi>& matrix,int i,int j)
{
if(i<0 || i>7 || j<0 || j>7) return ;
if(matrix[i][j] == 8) return;
if(matrix[i][j] != 2) return;
else matrix[i][j] = 8;
rec_func(matrix,i+1,j);
rec_func(matrix,i,j+1);
rec_func(matrix,i-1,j);
rec_func(matrix,i,j-1);
}
int main()
{
vector<vi> matrix({{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},});
rec_func(matrix,4,4);
prm(matrix);
return 0;
}