below program produce different output in onlline and offline compiler?
https://ide.geeksforgeeks.org/0c0cvzVxzk
in offline(codeblock,dec c++)-210
in online jdoodle and geeksforgeeks ide -470
for input:7
9
9
3
1 4 30
5 1 100
1 7 40
5 6 60
2 3 10
3 4 20
2 6 200
4 6 300
6 7 50
please someone explain why?
thank you
Valgrind says there is an invalid read on line 81.
This seems to happen when
cheapest[set2] is
-1.
found running throught valgrind
undefined behaviour caused by out-of-bounds access caused by copy-paste error.
76 77 78 79 80 81
|
if (cheapest[set1] == -1 ||
edge[cheapest[set1]].weight > edge[i].weight)
cheapest[set1] = i;
if (cheapest[set1] == -1 || //this should be set2
edge[cheapest[set2]].weight > edge[i].weight)
|
by the way, you've got leaks all over the place
http://www.cplusplus.com/forum/general/138037/#msg731921
Topic archived. No new replies allowed.