刘继才

导航

 

struct ET
{
ET(int i){
n=i;
};
ET(){
n=0;
};
int n;
};
bool cmp(const ET* lhs, const ET* rhs)
{//从大到小排列
return (lhs->n > rhs->n);
}
void __fastcall TForm18::Button2Click(TObject *Sender)
{
vector <ET*> v1;
vector <ET*>::iterator Iter1;
ET et[16];
for ( int i = 0 ; i <= 5 ; i++ )
{
et[i].n=2 * i;
v1.push_back( &et[i]);
}
int ii;
for ( ii = 0 ; ii <= 5 ; ii++ )
{
et[ii+5].n=2 * ii;
v1.push_back( &et[ii+5]);
// v1.push_back( ET(2 * ii + 1) );
}
cout << "Original vector v1 = ( " ;
for ( Iter1 = v1.begin( ) ; Iter1 != v1.end( ) ; Iter1++ )
cout << (*Iter1)->n << " ";
cout << ")" << endl;

sort( v1.begin( ), v1.end( ),cmp );
cout << "Sorted vector v1 = ( " ;
for ( Iter1 = v1.begin( ) ; Iter1 != v1.end( ) ; Iter1++ )
cout << (*Iter1)->n << " ";
cout << ")" << endl;
}

posted on 2017-05-25 08:19  刘继才  阅读(347)  评论(0编辑  收藏  举报