需要重载运算符'<',如下面的程序:
typedef struct { float w; int a, b; } edge; bool operator<(const edge &a, const edge &b) { return a.w < b.w; }
以后可以调用std::sort根据dge结构体w的值对进行排序,如:
std::sort(edges, edges + num_edges);