STL_알고리즘교환 (swap ranges)
3271 단어 STL교환 알고리즘STL_알고리즘swap_ranges
/**------http://blog.csdn.net/u010579068------**/
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<list>
#include<deque>
#include<algorithm>
using namespace std;
/*****************************************
//
swap_ranges(b,e,b2) // +
:
1、 swap()
2、
*****************************************/
/**----------------------------------------------------------------------------------
----------------------------------------------------------------------------------**/
/*************************************************************************************
std::swap_ranges algorithm
--------------------------------------------------------------------------------------
template < class ForwardIterator1, class ForwardIterator2 >
ForwardIterator2 swap_ranges ( ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2 );
//eg:
template<class ForwardIterator1, class ForwardIterator2>
ForwardIterator2 swap_ranges ( ForwardIterator1 first1, ForwardIterator1 last1,
ForwardIterator2 first2 )
{
while (first1!=last1) swap(*first1++, *first2++);
return first2;
}
*************************************************************************************/
int main()
{
vector<int> first (5,10); // first: 10 10 10 10 10
vector<int> second (7,33); // second: 33 33 33 33 33 5
vector<int>::iterator it;
swap_ranges(first.begin()+1, first.end()-1, second.begin());
// print out results of swap:
cout << "first contains:";
for (it=first.begin(); it!=first.end(); ++it)
cout << " " << *it;
cout << "
second contains:";
for (it=second.begin(); it!=second.end(); ++it)
cout << " " << *it;
cout << endl;
cout << endl;
/**-------------------------------------------------------------------**/
//swap_ranges , ,
int a[]={1,2,3,4,5,6,7};
int b[]={9,10,11,12};
vector<int> third (a,a+7);
deque<int> fourth(b,b+4);
deque<int>::iterator iter;
auto riter=swap_ranges(third.begin()+2, third.end()-3, fourth.rbegin()+1);
cout << "third contains:";
for (it=third.begin(); it!=third.end(); ++it)
cout << " " << *it;
cout << "
fourth contains:";
for (iter=fourth.begin(); iter!=fourth.end(); ++iter)
cout << " " << *iter;
cout << endl;
cout<<" : "<<*riter<<endl;
return 0;
}
/*******
Output:
first contains: 10 33 33 33 10
second contains: 10 10 10 33 33 33 33
third contains: 1 2 11 10 5 6 7
fourth contains: 9 4 3 12
: 9
**/
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
시각화(3D) > 정사각형 원추(격자 모양의 디폴트로 구성) > GitHub+STL 렌더링의 디스플레이 >make_cubeGroup_180520.py v0.1작업 환경 연관 Ref1. Ref2. Ref3. GitHub STL 렌더링 환경에 관계없이 Ref1 구현 결과를 렌더링합니다. Unity 렌더링을 사용하여 최대 52만 개를 시도했습니다. 그러나 유니티가 없는 환경에...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.