天天看點

C++ 對vector進行排序

title: C++ vector排序

tags: c++,vector,排序

grammar_cjkRuby: true

---

每次都要重複造輪子真的很累,是以用别人的吧。

目的:對vector進行排序

示例:

記得将

algorithm

這個頭檔案包括進去

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(void)
{
    vector <int> a;
    a.push_back(6);
    a.push_back(2);
    a.push_back(3);
    a.push_back(8);
    a.push_back(9);
    sort(a.begin(),a.end());
    for(int i=0;i<a.size();i++)
        cout<<a[i]<<" "<<endl;
        
    return 0;
}

>>> 2 3 8 6 9           

是不是很贊!!!

MARSGGBO 原創 2017-04-09

繼續閱讀