c - why this function always crashes? -
can tell me why fillpool
crashes? maybe there infinite recursion, where?
#include <stdio.h> #include <stdbool.h> #define n 5 bool isnotvalidindex(int row , int column) { if((row >= n || row < 0) || (column >= n || column < 0)) return true ; return false ; } void fillpool(int row , int column , int picture[n][n]) { if(isnotvalidindex(row , column)) return ; if(picture[row][column] == 0) return ; picture[row][column] = 2 ; fillpool(row + 1 , column , picture) ; fillpool(row - 1 , column , picture) ; fillpool(row ,column + 1 , picture) ; fillpool(row , column -1 , picture) ; }
you have infinite recursion because you're setting value of row/col "2" check "0". you're setting values 2 on , on again. infinite recursion happens because you're calling fillpool "row+1" fillpool "row-1" , infinite recursion (and same thing happen column+1 never reach there).
Comments
Post a Comment