Checking the Up direction .
if ( i - 1 >= 0 && maze [ i - 1 ] [ j ] == 1 && visited [ i - 1 ] [ j ] ) { Node temp1 = new Node ( i - 1 , j ) ; visited [ i - 1 ] [ j ] = false ; s . push ( temp1 ) ; } } else if ( d == 1 ) {