C++STL-list和set

来源:互联网 发布:oppo商城软件下载 编辑:程序博客网 时间:2024/05/18 04:55

C++STL-list和set


list

#include<cstdio>#include<iostream>#include<list>using namespace std;int main() {    list<int> a1;    list<int>::iterator it;    for (int i = 1; i <= 5; i++) {        a1.push_back(i);    }    for (it = a1.begin(); it != a1.end(); it++) {        printf("%d ", *it);    }    return 0;}

这里写图片描述


set

#include<cstdio>#include<iostream>#include<set>using namespace std;int main() {    for (int i = 1; i < 5; i++) {        for (int j = 1; j < 5; j++) {            set<int> s;            set<int>::iterator pos;            s.insert(i);            s.insert(j);            for (pos = s.begin(); pos != s.end(); pos++) {                int k = *pos;                printf("%d",k);            }            puts("");        }    }    return 0;}

这里写图片描述
可以看到 set内部有去重的作用


记录一下 以后可以看看

0 0