struct Edge
{
int src, dest, weight;
}; typedef struct Edge Edge;
struct Graph
{
int V, E;
Edge* edge;
}; typedef struct Graph Graph;
I have a graph struct like this. I am trying to use qsort to sort all the edges in increasing order of their weight. in main:
Graph* graph = (Graph*)malloc(sizeof(Graph));
qsort(graph->edge, graph->E, sizeof(graph->edge[0]), myComp);
Mycomp function:
int myComp(const void* a, const void* b)
{
Edge* a1 = (Edge*)a;
Edge* b1 = (Edge*)b;
return a1->weight > b1->weight;
}
After all, I tried to print every edge before and after the qsort, the order has been changed but it is not the correct order. Anyone can help with these? What part is wrong in my code?