Блог пользователя notAboAlmanalAnyMore

Автор notAboAlmanalAnyMore, история, 8 лет назад, По-английски

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

  • Проголосовать: нравится
  • +1
  • Проголосовать: не нравится

»
8 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

»
8 лет назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

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 лет назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

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 лет назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится
  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.