Hi everyone. I got a task to reverse number from index 2 to 5 for each row. I had try with the code but the solution wont appear. I dont know either i do right or wrong. Hope someone can help me. Thank you.
Oh, I see that I made a mistake. Line 40 should rather be: reverse(route[row].begin() + 2, route[row].begin() + 6);
Because the last iterator needs to be one beyond the last element to reverse.
Thanks nuderobmonkey. If you don't mind. I would like to ask another question also regards to reverse. I had try with the code but its weird. sometimes i could get the answer but when i run for another time error occurred. If not be mistaken, I think it related to
srand(time(null))
. Because when I disable
srand(time(null))
. I could get the answer but when I include those, error occurred. I don't know how to solved it.
i1 and i2 are two different random value positions from col 0 until col 9 for each row.
After i got two different random value, I do reverse number from index (i1 + 2) to index (i2 - 1) for each row.
After i reverse, I do swap next value at position i1 which is (i1 + 1) with value at position i2.
what output do you get
If I included srand(time(null)), the solution won't appear.
If I disable srand(time(null)), the solution appear but the random value is same for each run.
I had replace with NULL but error still occurred as previous.
and
warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
I suggest reposting your program in the 'Windows Program' forum if the error still will resist.
Okay i will post. Btw, thanks for your help. Really appreciated :)
null is defined in cstdlib among other places. check your includes, here is a link that may help..
It is often mistaken as a keyword, but its not really, its just a #define in that era of C++ at least...
nullptr actually IS a keyword, but you don't have it, seeing as how your compiler is almost old enough to attend middle school...
I mean I see that you have cstdlib, and it should be in there... zero will work, if you can't find the issue, but a new compiler would do you a lot better.