Qt std常用算法

 QStringList list;
    list<<"one"<<"two"<<"three";
    qDebug()<<list;
    QVector<QString> vect(3);
    std::copy(list.begin(),list.end(),vect.begin());
    qDebug()<<vect<<endl<<"__________";
    /*
     vect.append("four");
     list<<"five";
     ///false
     */
    //list的所有内容和后面等数量的项目进行比较
    bool ret=std::equal(list.begin(),list.end(),vect.begin());
    qDebug()<<vect<<ret;
    //QVector("one", "two", "three") true


    //find
    QList<QString>::iterator i= std::find(list.begin(),list.end(),"two");
    qDebug()<<*i;
    //"two"

    //fill
    std::fill(list.begin(),list.end(),"OK");
    qDebug()<<list;//("OK", "OK", "OK")

    //count
    QList<int> list_;
    list_<<1<<3<<5<<2<<1<<5;
    int countof3=std::count(list_.begin(),list_.end(),5);
    qDebug()<<"all count"<<countof3;//all count 2

    //升序排列
    std::stable_sort(list_.begin(),list_.end());
    qDebug()<<list_;//(1, 1, 2, 3, 5, 5) 前面的5排序依然在前面 后面出现的5的依然在后面

//反悔第一个出现对应值的位置 如果没有则返回对应值应该出现的位置
        QList<int>::iterator j =std::lower_bound(list_.begin(),list_.end(),4);
        list_.insert(j,4);
        qDebug()<<list_;
        //(1, 1, 2, 3, 4, 5, 5)

        //swap 交换
        double p1=3.55;
        double p2=3.66;
        std::swap(p1,p2);
        qDebug()<<"p1:"<<p1<<"___p2:"<<p2;//p1: 3.66 ___p2: 3.55
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Qt 本身并没有提供包络算法的实现,但可以使用第三方库来实现包络算法。下面介绍两种常用的第三方库: 1. CGAL CGAL 是一个计算几何算法库,提供了许多计算几何算法的实现,包括包络算法。使用 CGAL 实现包络算法的步骤如下: - 安装 CGAL 库并将其路径添加到编译器的 include 路径中; - 引入 CGAL 的头文件; - 定义点类型并创建点集; - 调用 CGAL 的包络算法函数计算凸包。 以下是一个使用 CGAL 实现包络算法的示例代码: ```c++ #include <CGAL/Exact_predicates_exact_constructions_kernel.h> #include <CGAL/convex_hull_2.h> #include <vector> typedef CGAL::Exact_predicates_exact_constructions_kernel K; typedef K::Point_2 Point_2; // 创建点集 std::vector<Point_2> points = {Point_2(0, 0), Point_2(1, 0), Point_2(0, 1), Point_2(1, 1)}; // 计算凸包 std::vector<Point_2> convex_hull; CGAL::convex_hull_2(points.begin(), points.end(), std::back_inserter(convex_hull)); ``` 2. Qhull Qhull 是一个计算几何库,提供了许多计算几何算法的实现,包括包络算法。 Qhull 的使用与 CGAL 类似,需要先安装 Qhull 库并将其路径添加到编译器的 include 路径中,然后引入 Qhull 的头文件并调用相应的函数计算凸包。以下是一个使用 Qhull 实现包络算法的示例代码: ```c++ #include <qhull/qhull.h> #include <vector> // 定义点类型 typedef qhull::coordT coordT; typedef std::vector<coordT> Point; typedef std::vector<Point> PointList; // 创建点集 PointList points = {{0, 0}, {1, 0}, {0, 1}, {1, 1}}; // 计算凸包 qhull::Qhull qhull; qhull.runQhull("", 2, points[0], points.size(), "qhull FA"); PointList vertices = qhull.getFacetVertices(); ``` 以上是两种常用的第三方库实现包络算法的方式,具体选择哪种库取决于个人偏好和项目需求。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值