• Qt使用std::sort进行排序


    参考:

    https://blog.csdn.net/u013346007/article/details/81877755

    https://www.linuxidc.com/Linux/2017-01/140078.htm

    https://www.cnblogs.com/gccbuaa/p/7111480.html

    sort和stable_sort都是全排序函数,但是sort是非稳定排序算法,而stable_sort是稳定排序算法。

    #include "paixu.h"
    #include <qstring.h>
    
    struct MyStruct
    {
        int id;
        QString name;
    };
    
    using namespace std;
    
    bool bigger_than(const MyStruct& s1, MyStruct& s2)
    {
        return (s1.id > s2.id);
    }
    
    bool little_than(const MyStruct& s1, MyStruct& s2)
    {
        return (s1.id <= s2.id);
    }
    
    paixu::paixu(QWidget *parent)
        : QMainWindow(parent)
    {
        ui.setupUi(this);
    
        QList<MyStruct> m_list;
        MyStruct ms1; ms1.id = 10; ms1.name = "10";
        MyStruct ms2; ms2.id = 110; ms2.name = "110";
        MyStruct ms3; ms3.id = 100; ms3.name = "100";
        MyStruct ms4; ms4.id = 120; ms4.name = "120";
        MyStruct ms5; ms5.id = 104; ms5.name = "104";
        MyStruct ms6; ms6.id = 108; ms6.name = "108";
        MyStruct ms7; ms7.id = 109; ms7.name = "109";
    
        m_list.append(ms1);
        m_list.append(ms2);
        m_list.append(ms3);
        m_list.append(ms4);
        m_list.append(ms5);
        m_list.append(ms6);
        m_list.append(ms7);
    
        std::sort(m_list.begin(), m_list.end(), bigger_than);
        int a = 100;
    
        std::sort(m_list.begin(), m_list.end(), little_than);
        a = 100;
    
    }
    
    paixu::~paixu()
    {
    
    }
  • 相关阅读:
    页面上有10个多选框,实现三个按钮(重置、反选、全选)功能
    鼠标点哪 哪出15*15的圆型div
    es写简单的留言板
    面试准备(3)事件循环
    面试准备(2)async+await的使用与原理
    面试准备(1)重排与重绘和验证码
    vue项目修改el-input样式
    echarts画雷达图详解
    决心
    国庆中秋
  • 原文地址:https://www.cnblogs.com/zhangxuan/p/10191917.html
Copyright © 2020-2023  润新知