美文网首页
Vector之类的遍历

Vector之类的遍历

作者: 人不知QAQ | 来源:发表于2019-12-30 17:07 被阅读0次

#include <iostream>

using namespace std;

#include <algorithm>

#include <vector>

#include<set>

#include <string>

class Cstudent

{

public:

Cstudent(int Id, string Name)

{

S_Id = Id;

S_Name = Name;

}

public:

int S_Id;

string S_Name;

};

bool Compare(const Cstudent &stuA, const Cstudent &stuB)

{

return (stuA.S_Id < stuB.S_Id);

}

int main()

{

// vector<int> vecInt;

// vecInt.push_back(1);

// vecInt.push_back(7);

// vecInt.push_back(3);

// vecInt.push_back(7);

// vecInt.push_back(9);

//

//// sort(vecInt.begin(), vecInt.end());//默认从小到大

vector <Cstudent> vecStu;

vecStu.push_back(Cstudent(2, "老二"));

vecStu.push_back(Cstudent(1, "老大"));

vecStu.push_back(Cstudent(3, "老三"));

vecStu.push_back(Cstudent(4, "老四"));

sort(vecStu.begin(), vecStu.end(), Compare);

for (vector<Cstudent>::iterator it = vecStu.begin(); it != vecStu.end(); it++)

{

cout << it->S_Id << ":" << it->S_Name << endl;

}

system("pause ");

return 0;

}

相关文章

  • Vector之类的遍历

    #include using namespace std; #include #include ...

  • vector遍历一个二维数组2018-10-14

    如何通过stl中vector遍历一个二维数组? vector中二维数组的遍历方法: 1、迭代器遍历 void re...

  • 线程安全list的遍历

    Vector Vector在迭代器遍历时,其他线程增删元素,会抛ConcurrentModificationExc...

  • 去干扰轮廓提取

    要求:提取目标轮廓排除干扰轮廓绘制轮廓 遍历器的使用vector::iterator itr;i...

  • vector的几种遍历方式

    相信每一个C++程序员都使用过STL库的vector,那么遍历一个vector有那些方法呢?哪个遍历的速度最快...

  • vector使用

    初始化 添加元素 vector的其他操作 vector ::size_type 遍历 迭代器 迭代器运算

  • 遍历二维数组

    vector& ops 使用for(auto op:ops)进行遍历,而不需要求出二维数组的长度

  • Easy_01

    两数之和 想法一:最直接的暴力解法。通过两层嵌套循环对数组进行遍历。 vector twoSum(vector &...

  • C++ 常用代码

    vector 迭代器遍历 C++ 函数模板 冒泡排序 快速排序

  • c++11:基于范围的for循环在codeblocks上出错

    先定义一个vector容器并存入10个数,然后基于范围的for循环遍历,代码如下: vector v1; for...

网友评论

      本文标题:Vector之类的遍历

      本文链接:https://www.haomeiwen.com/subject/oymmoctx.html