void spmtn1(int r, int c) { sq[r][c] = ' '; /* Mark the square we have visited */ /* Upon the destination point is found, check the current value of ctr1 with the value in * * the array, if the current value of ctr1 is less, update it and display message */ if (r == dRow && c == dCol) { if (ctr1 < sp[m]) { sp[m] = ctr1; printf("Shortest monotone path: %d\n", sp[m]); return; } } else ctr1++; /* To find the shortest monotone path from the origin point to destination point */ if (c > dCol && sq[r][c  1] != '#' && sq[r][c  1] != ' ') /* Either the point before the origin point or before the turning point has not been visited, * * only the origin point or turning point has been visited, so the next point it moving to can be * * less than or greater than or equal to the origin or turning point */ if (sq[r][c] == ' ' && sq[r][c + 1] != ' ') spmtn1(r, c  1); /* If the previous two points have been visited, then check if the previous point is greater than or equal * * to the one before then the next point it moving to must be greater than or equal to the previous point, * * so does less than or equal to. If not then the line will turn vertically or horizontally to next direction */ if (sq[r][c] == ' ' && sq[r][c + 1] == ' ') if ((sq[r][c] >= sq[r][c + 1] && sq[r][c  1] >= sq[r][c])  (sq[r][c] <= sq[r][c + 1] && sq[r][c  1] <= sq[r][c])) spmtn1(r, c  1); else if (c < dCol && sq[r][c + 1] != '#' && sq[r][c + 1] != ' ') /* Either the point before the origin point or before the turning point has not been visited, * * only the origin point or turning point has been visited, so the next point it moving to can be * * less than or greater than or equal to the origin or turning point */ if (sq[r][c] == ' ' && sq[r][c  1] != ' ') spmtn1(r, c + 1); /* If the previous two points have been visited, then check if the previous point is greater than or equal * * to the one before then the next point it moving to must be greater than or equal to the previous point, * * so does less than or equal to. If not then the line will turn vertically or horizontally to next direction */ if (sq[r][c] == ' ' && sq[r][c  1] == ' ') if ((sq[r][c] >= sq[r][c  1] && sq[r][c + 1] >= sq[r][c])  (sq[r][c] <= sq[r][c  1] && sq[r][c + 1] <= sq[r][c])) spmtn1(r, c + 1); else if (r > dRow && sq[r  1][c] != '#' && sq[r  1][c] != ' ') /* Either the point before the origin point or before the turning point has not been visited, * * only the origin point or turning point has been visited, so the next point it moving to can be * * less than or greater than or equal to the origin or turning point */ if (sq[r][c] == ' ' && sq[r + 1][c] != ' ') spmtn1(r  1, c); /* If the previous two points have been visited, then check if the previous point is greater than or equal * * to the one before then the next point it moving to must be greater than or equal to the previous point, * * so does less than or equal to. If not then the line will turn vertically or horizontally to next direction */ if (sq[r][c] == ' ' && sq[r + 1][c] == ' ') if ((sq[r][c] >= sq[r + 1][c] && sq[r  1][c] >= sq[r][c])  (sq[r][c] <= sq[r + 1][c] && sq[r  1][c] <= sq[r][c])) spmtn1(r  1, c); else if (r < dRow && sq[r + 1][c] != '#' && sq[r + 1][c] != ' ') /* Either the point before the origin point or before the turning point has not been visited, * * only the origin point or turning point has been visited, so the next point it moving to can be * * less than or greater than or equal to the origin or turning point */ if (sq[r][c] == ' ' && sq[r  1][c] != ' ') spmtn1(r + 1, c); /* If the previous two points have been visited, then check if the previous point is greater than or equal * * to the one before then the next point it moving to must be greater than or equal to the previous point, * * so does less than or equal to. If not then the line will turn vertically or horizontally to next direction */ if (sq[r][c] == ' ' && sq[r  1][c] == ' ') if ((sq[r][c] >= sq[r  1][c] && sq[r + 1][c] >= sq[r][c])  (sq[r][c] <= sq[r  1][c] && sq[r + 1][c] <= sq[r][c])) spmtn1(r + 1, c);
stack overflow
Page 1 of 13 Replies  1011 Views  Last Post: 08 May 2008  09:56 PM
#1
stack overflow
Posted 07 May 2008  10:10 PM
this whole part of code stack overflow. My intention was if this line "if (c > dCol && sq[r][c  1] != '#' && sq[r][c  1] != ' ')" is false then jump to the next else if statement. If this line "if (c> dCol && sq[r][c  1] != '#' && sq[r][c  1] != ' ')" is true, when the origin point start moving or when turning point takes place, this line "if (sq[r][c] == ' ' && sq[r][c + 1] != ' ')" will always be true, IE execute this line "spmtn1(r, c  1)". when the point moves some where in the middle of the line, no turning takes place, then this line "if (sq[r][c] == ' ' && sq[r][c + 1] == ' ')" will become true, the previous one will become false. then do the check on this line "if ((sq[r][c]>= sq[r][c + 1] && sq[r][c  1]>= sq[r][c])  (sq[r][c] <= sq[r][c + 1] && sq[r][c  1] <= sq[r][c]))", if it's true then execute this line "spmtn1(r, c  1);", if it's false then jump to next else if statement.
Replies To: stack overflow
#2
Re: stack overflow
Posted 08 May 2008  07:13 PM
kckc314, on 7 May, 2008  10:10 PM, said:
this whole part of code stack overflow. My intention was if this line "if (c > dCol && sq[r][c  1] != '#' && sq[r][c  1] != ' ')" is false then jump to the next else if statement. If this line "if (c> dCol && sq[r][c  1] != '#' && sq[r][c  1] != ' ')" is true, when the origin point start moving or when turning point takes place, this line "if (sq[r][c] == ' ' && sq[r][c + 1] != ' ')" will always be true, IE execute this line "spmtn1(r, c  1)". when the point moves some where in the middle of the line, no turning takes place, then this line "if (sq[r][c] == ' ' && sq[r][c + 1] == ' ')" will become true, the previous one will become false. then do the check on this line "if ((sq[r][c]>= sq[r][c + 1] && sq[r][c  1]>= sq[r][c])  (sq[r][c] <= sq[r][c + 1] && sq[r][c  1] <= sq[r][c]))", if it's true then execute this line "spmtn1(r, c  1);", if it's false then jump to next else if statement.
void spmtn1(int r, int c) { sq[r][c] = ' '; /* Mark the square we have visited */ /* Upon the destination point is found, check the current value of ctr1 with the value in * * the array, if the current value of ctr1 is less, update it and display message */ if (r == dRow && c == dCol) { if (ctr1 < sp[m]) { sp[m] = ctr1; printf("Shortest monotone path: %d\n", sp[m]); return; } } else ctr1++; /* To find the shortest monotone path from the origin point to destination point */ if (c > dCol && sq[r][c  1] != '#' && sq[r][c  1] != ' ') /* Either the point before the origin point or before the turning point has not been visited, * * only the origin point or turning point has been visited, so the next point it moving to can be * * less than or greater than or equal to the origin or turning point */ if (sq[r][c] == ' ' && sq[r][c + 1] != ' ') spmtn1(r, c  1); /* If the previous two points have been visited, then check if the previous point is greater than or equal * * to the one before then the next point it moving to must be greater than or equal to the previous point, * * so does less than or equal to. If not then the line will turn vertically or horizontally to next direction */ if (sq[r][c] == ' ' && sq[r][c + 1] == ' ') if ((sq[r][c] >= sq[r][c + 1] && sq[r][c  1] >= sq[r][c])  (sq[r][c] <= sq[r][c + 1] && sq[r][c  1] <= sq[r][c])) spmtn1(r, c  1); else if (c < dCol && sq[r][c + 1] != '#' && sq[r][c + 1] != ' ') /* Either the point before the origin point or before the turning point has not been visited, * * only the origin point or turning point has been visited, so the next point it moving to can be * * less than or greater than or equal to the origin or turning point */ if (sq[r][c] == ' ' && sq[r][c  1] != ' ') spmtn1(r, c + 1); /* If the previous two points have been visited, then check if the previous point is greater than or equal * * to the one before then the next point it moving to must be greater than or equal to the previous point, * * so does less than or equal to. If not then the line will turn vertically or horizontally to next direction */ if (sq[r][c] == ' ' && sq[r][c  1] == ' ') if ((sq[r][c] >= sq[r][c  1] && sq[r][c + 1] >= sq[r][c])  (sq[r][c] <= sq[r][c  1] && sq[r][c + 1] <= sq[r][c])) spmtn1(r, c + 1); else if (r > dRow && sq[r  1][c] != '#' && sq[r  1][c] != ' ') /* Either the point before the origin point or before the turning point has not been visited, * * only the origin point or turning point has been visited, so the next point it moving to can be * * less than or greater than or equal to the origin or turning point */ if (sq[r][c] == ' ' && sq[r + 1][c] != ' ') spmtn1(r  1, c); /* If the previous two points have been visited, then check if the previous point is greater than or equal * * to the one before then the next point it moving to must be greater than or equal to the previous point, * * so does less than or equal to. If not then the line will turn vertically or horizontally to next direction */ if (sq[r][c] == ' ' && sq[r + 1][c] == ' ') if ((sq[r][c] >= sq[r + 1][c] && sq[r  1][c] >= sq[r][c])  (sq[r][c] <= sq[r + 1][c] && sq[r  1][c] <= sq[r][c])) spmtn1(r  1, c); else if (r < dRow && sq[r + 1][c] != '#' && sq[r + 1][c] != ' ') /* Either the point before the origin point or before the turning point has not been visited, * * only the origin point or turning point has been visited, so the next point it moving to can be * * less than or greater than or equal to the origin or turning point */ if (sq[r][c] == ' ' && sq[r  1][c] != ' ') spmtn1(r + 1, c); /* If the previous two points have been visited, then check if the previous point is greater than or equal * * to the one before then the next point it moving to must be greater than or equal to the previous point, * * so does less than or equal to. If not then the line will turn vertically or horizontally to next direction */ if (sq[r][c] == ' ' && sq[r  1][c] == ' ') if ((sq[r][c] >= sq[r  1][c] && sq[r + 1][c] >= sq[r][c])  (sq[r][c] <= sq[r  1][c] && sq[r + 1][c] <= sq[r][c])) spmtn1(r + 1, c);
hi guys, i have fixed the stack overflow issues and it doesn't happen for the time being. now the problem is this part of code doesn't do anything. no output solution. pls advise.
#3
Re: stack overflow
Posted 08 May 2008  08:05 PM
Okay, first off, it's pretty much impossible to read that code because of the comment density.
Anyway, I'm gonna go ahead and say that your issue is probably due to lack of curly brackets. Your tabbing makes it seem like you have a few large groups of ifs with several ifs inside each one, but you don't have brackets, so they will not be interpreted that way.
Per
Anyway, I'm gonna go ahead and say that your issue is probably due to lack of curly brackets. Your tabbing makes it seem like you have a few large groups of ifs with several ifs inside each one, but you don't have brackets, so they will not be interpreted that way.
Per
#4
Re: stack overflow
Posted 08 May 2008  09:56 PM
pertheusual, on 8 May, 2008  08:05 PM, said:
Okay, first off, it's pretty much impossible to read that code because of the comment density.
Anyway, I'm gonna go ahead and say that your issue is probably due to lack of curly brackets. Your tabbing makes it seem like you have a few large groups of ifs with several ifs inside each one, but you don't have brackets, so they will not be interpreted that way.
Per
Anyway, I'm gonna go ahead and say that your issue is probably due to lack of curly brackets. Your tabbing makes it seem like you have a few large groups of ifs with several ifs inside each one, but you don't have brackets, so they will not be interpreted that way.
Per
i have grabbed part of the code and change it in the following way:
if (c < dCol && sq[r][c + 1] != '#' && sq[r][c + 1] != ' ') { >if this line is false then jump to the next else if, but if it is true if (sq[r][c] == ' ' && sq[r][c  1] != ' ') {>if this line is true then execute the statement, the below if statements won't be executed, but if it is false spmtn1(r, c + 1); } } if (c < dCol && sq[r][c + 1] != '#' && sq[r][c + 1] != ' ') {>as this line still remain as true, same first if statement as above if (sq[r][c] == ' ' && sq[r][c  1] == ' ') {>if the above second if statement is false then this line will always be true if ((sq[r][c] >= sq[r][c  1] && sq[r][c + 1] >= sq[r][c])  (sq[r][c] <= sq[r][c  1] && sq[r][c + 1] <= sq[r][c])) {>then check this line, if it is true then execute the statement, if it is false then jump to the next else if spmtn1(r, c + 1); } } } else if
i think still having errors according to the logic as it still not working. pls advise. thanks in advance.
Page 1 of 1
