如何利用C++list容器对结构体进行排序

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/a_studycx/article/details/82378977

list容器已经给出排序函数sort。

只需要重载比较函数就可以。

typedef struct inforNode 
{
    unsigned char name[20];
    unsigned char number[10];
    unsigned char age[3];
    unsigned char country[20];
    struct Node* pNext;
}InforNode;

typedef list<InforNode> NodeList;

bool operator<(const InforNode& lhs, const InforNode& rhs)
{
   if(strcmp((const char*)lhs.name,(const char*)rhs.name) < 0)
   {
       return true;
   }
   return false;
}

猜你喜欢

转载自blog.csdn.net/a_studycx/article/details/82378977