notAboAlmanalAnyMore's blog

By notAboAlmanalAnyMore, history, 8 years ago, In English

Hello ..
this is what I'm telling my code to output :3 :

AND this is the output !!!

like you see , there is equality between temp and check but the output is different !!
full code : http://pastebin.com/8v0GgHXd
Thank you in advance :D

»
8 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by notAboAlmanalAnyMore (previous revision, new revision, compare).

»
8 years ago, # |
  Vote: I like it +3 Vote: I do not like it

You're using the same vis array between the two different calls. If you want to reproduce the same results, you should at least clear the array vis between the two calls.

  • »
    »
    8 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    I'm clearing the array vis between the two calls by " memset(vis, 0, sizeof(vis)); "
    didn't you see it ?! :p

»
8 years ago, # |
  Vote: I like it +3 Vote: I do not like it

you must put another memset between - temp = check(i); - and cout << temp << " " << check(i) << endl ;

because you are calling check( i ) two times and v is changing

»
8 years ago, # |
  Vote: I like it +3 Vote: I do not like it
  1. Your check function is not pure: it modifies global state (specifically, the vis array). Naturally, an impure function is not guaranteed to return the same value each time it is called with the same arguments (that is, it is not a function in mathematical sense).

  2. If you call check on a vertex with no outgoing edges, the result is unspecified (no return statement).

  3. And, contrary to what you state in another comment thread, there is no memset between two calls to check, which are at lines 54 and 55.