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内部有去重的作用
记录一下 以后可以看看