English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
C ++ 목록 병합 함수는 요소를 목록 y에서 지정된 위치의 목록 컨테이너로 전송하여 두 목록의 크기가 모두 변경됩니다.
void splice(iterator pos, list& y); void splice(iterator pos, list& y, iterator pos1); void splice(iterator pos, list& y, iterator first, iterator last);
y: 내용 전송 타입과 동일한 목록 객체입니다.
pos: y 요소가 삽입될 위치를 정의합니다.
pos1:pos1지정된 요소가 전송됩니다.
(first,last):그것은 전달할 요소의 범위를 정의합니다.
그것은 어떤 값도 반환하지 않습니다.
그럼에 따라 간단한 예제를 보겠습니다
#include <iostream> #include<list> using namespace std; int main() { list<int> li={1,2,3,4}; list<int> li1={5,6,7,8}; list<int>::iterator itr=li.begin(); li.splice(itr,li1); for(list<int>::iterator itr=li.begin();itr!=li.end();++itr) std::cout << *itr << " "; return 0; }
출력:
5 6 7 8 1 2 3 4
그럼에 따라 간단한 예제를 보겠습니다
#include <iostream> #include<list> using namespace std; int main() { list<int> li={9,11,12,13}; list<int> li1={10,6,7,8}; list<int>::iterator itr=li.begin(); list<int>::iterator itr1=li1.begin(); ++itr; li.splice(itr,li1,itr1); for(list<int>::iterator itr=li.begin();itr!=li.end();++itr) std::cout << *itr << " "; return 0; }
출력:
9 10 11 12 13
그럼에 따라 간단한 예제를 보겠습니다
#include <iostream> #include<list> using namespace std; int main() { list<string> li={"programming language"}; list<string> li1={"java","is","a","language"}; list<string>::iterator itr = li.begin(); list<string>::iterator itr1=li1.begin(); advance(itr1,3); li.splice(itr,li1,li1.begin(),itr1); for(list<string>::iterator itr=li.begin();itr!=li.end();++itr) std::cout << *itr << " "; return 0; }
출력:
java는 프로그래밍 언어입니다