bool IsOdd(int i )
{
return ( (i%2)==1) ;
}
int main()
{
vector<int> v{1,3,7,9,5,5,3,1} ;
list<int> l{2,6,8,10,4,12,14,16} ;
std::sort(v.begin(),v.end()) ;
unique_copy(v.begin(),v.end(),l.begin()) ;
for(auto itx=l.begin();itx != l.end();itx++)
cout << *itx << endl ;
cout << "==================================" << endl ;
vector<int> x{ 2,3,4,5,6,4,2,1,8,9,7,10,15,14,13,12,11,6,6,3,1,6} ;
sort(x.begin(),x.end()) ;
list<int> res{ 1,3,5 } ;
unique_copy(x.begin(),x.end(),back_inserter(res)) ;
for(auto itx=res.begin();itx != res.end();itx++)
cout << *itx << endl ;
cout << "==================================" << endl ;
int z[10] = { 0 } ;
int *p1 = &z[0] ;
int *p2 = &z[6] ;
cout << distance( p1,p2 ) << endl ;
cout << "==================================" << endl ;
vector<int> y {2,3,4,5,1,7,9,2,4,6,9,11,12,15} ;
auto it1 = y.begin() ;
auto it2 = y.end() ;
while(1)
{
auto it = std::find_if( it1,it2,IsOdd ) ;
if( it == it2)
break ;
cout << "The Odd is:" << *it << endl ;
cout << "The distance is:" << distance( it1,it) << endl ;
it1 = it1 + distance( it1,it) + 1 ;
} //while
}
Output :
1
3
5
7
9
12
14
16
==================================
1
3
5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
==================================
6
==================================
The Odd is:3
The distance is:1
The Odd is:5
The distance is:1
The Odd is:1
The distance is:0
The Odd is:7
The distance is:0
The Odd is:9
The distance is:0
The Odd is:9
The distance is:3
The Odd is:11
The distance is:0
The Odd is:15
The distance is:1
留言列表