Ad
  • Custom User Avatar

    Yep. https://www.bell-labs.com/usr/dmr/www/cman.pdf

    7.11 expression && expression
    The && operator returns 1 if both its operands are non-zero, 0 otherwise. Unlike &, && guarantees left-to-right
    evaluation; moreover the second operand is not evaluated if the first operand is 0.
    The operands need not have the same type, but each must have one of the fundamental types or be a pointer.

    7.12 expression || expression
    The || operator returns 1 if either of its operands is non-zero, and 0 otherwise. Unlike | , || guarantees left-to-right
    evaluation; moreover, the second operand is not evaluated if the value of the first operand is non-zero.
    The operands need not have the same type, but each must have one of the fundamental types or be a pointer.

  • Custom User Avatar

    If p is NULL then it is falsy; and the && operator uses lazy evaluation, if its left operand is false, the expression evaluates to false without actually running the evaluation of the right operand. The same thing is true for the || operator as well, if the left operand is true, it returns true without trying to evaluate the right operand.

  • Custom User Avatar

    Any live cell with two or three live neighbours lives on to the next generation.
    Any dead cell with exactly three live neighbours becomes a live cell.

    there needs to be 3 live cells for a dead cell to become alive. 2 is not enough

  • Custom User Avatar

    The expected output you've listed is wrong as well. The actual expected output for that test is:

    0 1 0
    0 0 1
    1 1 1
    

    I could be wrong, but it looks like you are progressively changing the input, and that is causing errors as your process each cell. Everything in the universe happens all at once for each generation, what happens in one cell for the next generation shouldn't effect what happens in the next cell for that current generation.

    This gen    Next Gen
    1 0 0       0 1 0   //The cell in [0,0] dies because there is only one living neighbor at [1,1], the cell at [0,1] becomes alive because there are exactly 3 neighbors at [0,0], [1,1], [1,2]. The cell at [0,2]
    0 1 1  -->  0 0 1   //only has two neighbors at [1,1] and [1,2]. notice how the neighbor at [0,0] still counts for [0,1], even though [0,0] will die for the next generation. And the cell at [0,1] will be alive
    1 1 0       1 1 1   //next generation, but it doesn't count as a neighbor for [0,2] this generation. And so on for the rest of the cells in the universe.
    
    
  • Custom User Avatar

    the Queue elements are pointers (void*) but you are storing integers instead. You need to take the address with & when you enqueue, and dereference with * when you dequeue. see my fork of your solution