我正在尝试使用 对结构数组进行排序qsort,但它没有正确对内容进行排序。结构节点由起始顶点、结束顶点以及从顶点“a”到达顶点“b”的成本组成。
我正在编写克鲁斯卡尔算法的代码
#include <stdio.h>
#include <stdlib.h>
int v, e;
typedef struct node {
int a;
int b;
int cost;
} node;
int compare(const void *a, const void *b) {
const node *x = *(node **)a;
const node *y = *(node **)b;
return (x->cost > y->cost) ? 1 : 0;
}
int main() {
scanf("%d %d", &v, &e);
int i;
node *arr[e];
for (i = 0; i < e; i++) {
int a, b, cost;
scanf("%d %d %d", …Run Code Online (Sandbox Code Playgroud)