N
nkw
Hi,
I'm new to C and I'm stuck in working out the logic code for a cyclic
array.
I have an array of 5 cells, starting at index cell 0 and last cell is
4.
ie
0 1 2 3 4 0 1 ..... and so on
My problem is at the boundaries,
When I'm on Cell 0, I want to check cell 2 and Cell 4 then do
something
When I'm on Cell 4, I want to check cell 3 and Cell 0 then do
something
I have psuedo code something like this
cell[5];
for (col=0, col<5; col++)
if cell[0]=='1' && if cell[2]=='1' && if cell[4]=='1'
then do something
if cell[4]=='1' && if cell[3]=='1' && if cell[0]=='1'
then do something
if cell[0]=='0' && if cell[2]=='0' && if cell[4]=='0'
then do something
if cell[4]=='0' && if cell[3]=='0' && if cell[0]=='0'
then do something
......
My problem:
a) Is it correct to use:
if (cell[0]=='1' && cell[col+1]=='1' && cell[ENDCELL]=='1')
if (cell[ENDCELL]=='1' && cell[ENDCELL-1]=='1' && cell[0]=='1')?
b) Is there am effiecient way to check for conditions at the end
points or do I have to state each end point case ? In this post, I'm
checking for 1 and 0 for simplicity.
Can anyone help out ?
Thanks in advance
Nat
I'm new to C and I'm stuck in working out the logic code for a cyclic
array.
I have an array of 5 cells, starting at index cell 0 and last cell is
4.
ie
0 1 2 3 4 0 1 ..... and so on
My problem is at the boundaries,
When I'm on Cell 0, I want to check cell 2 and Cell 4 then do
something
When I'm on Cell 4, I want to check cell 3 and Cell 0 then do
something
I have psuedo code something like this
cell[5];
for (col=0, col<5; col++)
if cell[0]=='1' && if cell[2]=='1' && if cell[4]=='1'
then do something
if cell[4]=='1' && if cell[3]=='1' && if cell[0]=='1'
then do something
if cell[0]=='0' && if cell[2]=='0' && if cell[4]=='0'
then do something
if cell[4]=='0' && if cell[3]=='0' && if cell[0]=='0'
then do something
......
My problem:
a) Is it correct to use:
if (cell[0]=='1' && cell[col+1]=='1' && cell[ENDCELL]=='1')
if (cell[ENDCELL]=='1' && cell[ENDCELL-1]=='1' && cell[0]=='1')?
b) Is there am effiecient way to check for conditions at the end
points or do I have to state each end point case ? In this post, I'm
checking for 1 and 0 for simplicity.
Can anyone help out ?
Thanks in advance
Nat