MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / is_safe

Function is_safe

CSES/Intro/CheesboardAndQueens.cc:8–27  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6static int cnt = 0;
7
8bool is_safe(int row,int col){
9 int i, j;
10
11 /* Check this row on left side */
12 for (i = 0; i < col; i++)
13 if (grid[row][i] == 'G')
14 return false;
15
16 /* Check upper diagonal on left side */
17 for (i = row, j = col; i >= 0 && j >= 0; i--, j--)
18 if (grid[i][j] == 'G')
19 return false;
20
21 /* Check lower diagonal on left side */
22 for (i = row, j = col; j >= 0 && i < N; i++, j--)
23 if (grid[i][j] == 'G')
24 return false;
25
26 return true;
27}
28
29void dfs(int row,int col) {
30 if (col >= N) { cnt++; return; }

Callers 1

dfsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected