#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
#define eps 1e-10
#define bug(a) cout<<"# "<<a<<endl;
#define bug2(a,b) cout<<"# "<<a<<" # "<<b<<endl;
#define bug3(a,b,c) cout<<"# "<<a<<" # "<<b<<" # "<<c<<endl;
vector<int> v;
void test1()
{
for(int i=0;i<7;i++)
v.push_back(i);
try
{
int iVa1=v[7];
int iVa2=v.at(7);
}
catch(const exception& e)
{
cout<<e.what();
}
}
void test2()
{
v.clear();
for(int i=1;i<=10;i++)
v.push_back(i);
for(int i=0;i<v.size();i++)
cout<<v[i]<<" "; bug("");
vector<int>::iterator it;
for(it=v.begin();it!=v.end();++it)
cout<<*it<<" ";
bug("");
bug((v.back()));
v.pop_back();
bug(v.back());
v.erase(v.end()-1);
bug(v.back());
bug(v.front());
v.erase(v.begin());
bug(v.front());
}
void test3()
{
v=vector<int>();
for(int i=0;i<v.size();i++)
cout<<v.at(i)<<" ";
cout<<endl;
for(int i=0;i<=10;i++)
v.push_back(i);
for(int i=0;i<v.size();i++)
cout<<v.at(i)<<" ";
cout<<endl;
v.insert(v.begin()+1,1000);
for(int i=0;i<v.size();i++)
cout<<v.at(i)<<" ";
cout<<endl;
vector<int>::iterator it;
it=v.erase(v.begin()+5);
cout<<*it<<endl;
for(int i=0;i<v.size();i++)
cout<<v.at(i)<<" ";
cout<<endl;
it=v.erase(v.end()-5);
cout<<*it<<endl;
for(int i=0;i<v.size();i++)
cout<<v.at(i)<<" ";
cout<<endl;
}
void insertsort(int x)
{
v.insert(lower_bound(v.begin(),v.end(),x),x);
}
void test4()
{
v.clear();
int a[]={1,5,8,4,8,9,5};
for(int i=0;i<7;i++)
insertsort(a[i]);
for(int i=0;i<v.size();i++)
cout<<v[i]<<" ";
cout<<endl;
}
int main()
{
test4();
return 0;
}
引用