C++ 按对象的子对象对对象进行排序
我想根据extnodeID引用的NodeId对extnodeID列表进行排序。 代码可能会有错误,因为它只是一个示例C++ 按对象的子对象对对象进行排序,c++,sorting,object,C++,Sorting,Object,我想根据extnodeID引用的NodeId对extnodeID列表进行排序。 代码可能会有错误,因为它只是一个示例 class Node { public: int nodeID; /* unique node ID */ std::list<int> extnodeID; /* the node ID of other nodes */ int length;
class Node {
public:
int nodeID; /* unique node ID */
std::list<int> extnodeID; /* the node ID of other nodes */
int length; /* non-unique value */
}
int main(){
std::vector<Node> nodes;
for(int i=0; i<3; i++){
Node tempnode;
tempnode.nodeID = i;
length = rand() % 6;
}
}
类节点{
公众:
int nodeID;/*唯一节点ID*/
std::list extnodeID;/*其他节点的节点ID*/
int length;/*非唯一值*/
}
int main(){
std::向量节点;
对于(int i=0;我问Lucas什么?我想知道如何根据ExtNodeId表示的长度对ExtNodeId进行排序。您看过std::sort
和一些示例吗?使用std::sort
并在第3个参数中传递比较函数,然后在该函数中编写排序逻辑。如果遇到如果有任何问题,请在问题中附上比较器代码。谢谢