


一个例子
#include <iostream>
#include <algorithm>
#include <vector>
#include <iterator>
using namespace std;
int main()
{
int a[5]={1,2,3,2,5};
int b[6]={1,2,3,2,5,6};
ostream_iterator<int>oit(cout, ",");
int *p = remove(a, a+5, 2);
cout<<"1)";
copy(a, a+5, oit);
cout<<endl;
cout<<"2)"<<p-a<<endl;
vector<int>v(b, b+6);
remove(v.begin(), v.end(), 2);
cout<<"3)";
copy(v.begin(), v.end(), oit);cout<<endl;
cout<<"4)";
cout<<v.size()<<endl;
return 0;
}
1)1,3,5,2,5,
2)3
3)1,3,5,6,5,6,
4)6
这里remove并没有把这个元素删掉然后把数组变小,而是把这个元素的位置变成一个空位置,然后把后面的元素填充到前面去




#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main()
{
string str = "231";
char szStr[] = "324";
while(next_permutation(str.begin(), str.end())){
cout<<str<<endl;
}
cout<<"***"<<endl;
while(next_permutation(szStr, szStr+3)){
cout<<szStr<<endl;
}
sort(str.begin(), str.end());
cout<<"***"<<endl;
while(next_permutation(str.begin(), str.end()))
{
cout<<str<<endl;
}
return 0;
}
312
321
***
342
423
432
***
132
213
231
312
321
#include <iostream>
#include <algorithm>
#include <string>
#include <list>
#include <iterator>
using namespace std;
int main()
{
int a[]={8,7,10};
list<int> ls(a, a+3);
while(next_permutation(ls.begin(), ls.end()))
{
list<int>::iterator i;
for (i = ls.begin(); i != ls.end(); ++i) {
cout<<*i<<" ";
}
cout<<endl;
}
}
8 10 7
10 7 8
10 8 7


#include <iostream>
#include <algorithm>
using namespace std;
class MyLess{
public:
bool operator()(int n1, int n2)
{
return (n1%10)<(n2%10);
}
};
int main()
{
int a[]={14,2,9,111,78};
sort(a, a+5, MyLess());
int i;
for (int i = 0; i < 5; ++i) {
cout<<a[i]<<" ";
}
cout<<endl;
sort(a, a+5, greater<int>());
for (int i = 0; i < 5; ++i) {
cout<<a[i]<<" ";
}
}
111 2 14 78 9
111 78 14 9 2

















这两节课真的。。。。图片太多了。。。终于讲完了,好长