C++学习-List学习

#include <Qlist>
#include <list>
#include <functional> //仿函数要的头文件
#include <string>

模板函数

template <class _Ty>

void PrintfList(QList<_Ty> data)
{
   
    qDebug() << "模板函数" << "\t";
    for (auto v : data)
    {
   
        qDebug() << v << "\t";
    }
    qDebug()  << "\n";
}

基本操作

QString tmepList[5] = {
   "3医院","1学校","9学位","0衣","2行"};
    QList<QString> strList;
    for (int i = 0; i < 5; i++) {
   
        strList.push_back(tmepList[i]);//尾插法
    }
    strList.push_front("10胶水"); //头插法


    for (int i = 0; i < strList.size(); i++) {
   
        qDebug() << strList[i] << "\n";
    }

    //模板打印
    PrintfList(strList);

    //迭代器打印
    qDebug() << "迭代器打印";
    for (QList<QString>::iterator iter = strList.begin(); iter != strList.end(); iter++) {
   
        qDebug() << *iter << "\n";
    }

    //排序
    strList.sort();
    PrintfList(strList);
    //
    qDebug() << "反转打印";
    strList.reserve(strList.size());
    PrintfList(strList);


    //边打印边删除的方式
    //从尾巴先打印再删除
//    while(!strList.empty()) {
   
//        qDebug() << strList.back() << "\t";
//        strList.pop_back();
//    }
//    qDebug() << "strList size:" <<strList.size()<<"\n";

    while(!strList.empty()) {
   
        qDebug() << strList.front() << "\t";
        strList.pop_front();
    }
    qDebug() << "strList size:" <<strList.size()<<"\n";


相关推荐

  1. C++学习-List学习

    2024-01-10 12:42:03       51 阅读
  2. C++_List学习

    2024-01-10 12:42:03       29 阅读
  3. c++学习:容器list实战(获取目录返回容器list

    2024-01-10 12:42:03       50 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-10 12:42:03       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-10 12:42:03       100 阅读
  3. 在Django里面运行非项目文件

    2024-01-10 12:42:03       82 阅读
  4. Python语言-面向对象

    2024-01-10 12:42:03       91 阅读

热门阅读

  1. Hive之set参数大全-7

    2024-01-10 12:42:03       45 阅读
  2. Redis 简介

    2024-01-10 12:42:03       53 阅读
  3. HTTP 请求参数之三种格式

    2024-01-10 12:42:03       60 阅读
  4. Vue应用多语言支持工程化最佳实践

    2024-01-10 12:42:03       69 阅读
  5. NSIS 安装windows 安装包(包括QT和MFC)

    2024-01-10 12:42:03       44 阅读
  6. 学习紫微斗数之感悟

    2024-01-10 12:42:03       51 阅读
  7. 5个你不能错过的在线教育开源项目

    2024-01-10 12:42:03       63 阅读
  8. Oracle 基本命令

    2024-01-10 12:42:03       57 阅读
  9. 2024.1.9

    2024-01-10 12:42:03       61 阅读