Now we are talking.... See? You have wasted a whole day with writing non relevant post until we finally get some code to run and inspect.... Now we can work... This is so frustrating if people tell they run "this code" and the it comes out, that they modified it and it is completely different...
Now i get also your result. The first thing i am thinking of is the web based ides run all on linux and you and me are running windows.
They are running gcc 5.4, you are running gcc4.6, i am running gcc5.1, gcc 6.4 and mingw64-gcc7.1 on all this compiler on windows the result is the same.
Now lets look at the code, where is the possibility that something goes wrong? My first guess is "qsort"
i made a breakpoint after the function call.
on windows:
p graph->edge[0]
$1 = {src = 3, dest = 6, weight = 5}
p graph->edge[1]
$2 = {src = 0, dest = 2, weight = -11}
p graph->edge[2]
$3 = {src = 8, dest = 6, weight = 3}
on linux:
p graph->edge[0]
$2 = {src = 0, dest = 2, weight = -11}
graph->edge[1]]
$4 = {src = 8, dest = 6, weight = 3}
p graph->edge[2]]
$6 = {src = 2, dest = 6, weight = 4}
there is something fishy... Just to make things clear, this is not a codeblocks problem, but a compiler, stdlib problem...
sorted list on linux:
0: -11
1: 3
2: 4
3: 4
4: 5
5: 5
6: 5
7: 10
8: 10
9: 11
10: 11
11: 11
12: 12
13: 13
sorted list in windows:
0: 5
1: -11
2: 3
3: 4
4: 5
5: 10
6: 5
7: 10
8: 4
9: 11
10: 11
11: 11
12: 12
13: 13
if i use this sort function:
struct {
bool operator()(const Edge a1,const Edge b1) const
{
return a1.weight < b1.weight;
}
} customLess;
std::sort(graph->edge, graph->edge + graph->E, customLess);
all works as expected:
0 -- 2 == -11
8 -- 6 == 3
2 -- 6 == 4
7 -- 8 == 4
3 -- 6 == 5
0 -- 1 == 10
1 -- 4 == 11
5 -- 6 == 11
The question now is, why does qsort on windows does not work?....