View Single Post
  #1 (permalink)  
Old 05-09-2008, 09:41 AM
kckc314 kckc314 is offline
Novice
Join Date: Apr 2008
Posts: 14
iTrader: (0)
kckc314 is on a distinguished road
recursion function in C

what's wrong with the following code as it is not working.
Code:
if (c> dCol && sq[r][c - 1] != '#' && sq[r][c - 1] != ' ') {
   if (sq[r][c] == ' ' && sq[r][c + 1] != ' ') {
      spmtn1(r, c - 1);
   }
}
if (c> dCol && sq[r][c - 1] != '#' && sq[r][c - 1] != ' ') {
   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] != ' ') { -->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
and this one also as it is not working.
Code:
if (c> dCol && ((sq[r][c - 1] != '#' && sq[r][c - 1] != ' ') || (sq[r + 1][c] != '#' && sq[r + 1][c] != ' ') || (sq[r][c + 1] != '#' && sq[r][c + 1] != ' ') || (sq[r - 1][c] != '#' && sq[r - 1][c] != ' ')) && sq[r][c - 1] <= sq[r + 1][c] && sq[r][c - 1] <= sq[r][c + 1] && sq[r][c - 1] <= sq[r - 1][c])
   spmw1(r, c - 1);
else
if (c < dCol && ((sq[r][c + 1] != '#' && sq[r][c + 1] != ' ') || (sq[r - 1][c] != '#' && sq[r - 1][c] != ' ') || (sq[r][c - 1] != '#' && sq[r][c - 1] != ' ') || (sq[r + 1][c] != '#' && sq[r + 1][c] != ' ')) && sq[r][c + 1] <= sq[r - 1][c] && sq[r][c + 1] <= sq[r][c - 1] && sq[r][c + 1] <= sq[r + 1][c])
   spmw1(r, c + 1);
else
if

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote