rotate

WanJu Kim·2023년 1월 6일

Function

목록 보기
4/7

rotate

algorithm 라이브러리 안에 있다. 컨테이너 내의 원소를 일정 크기만큼 회전시켜주는 함수. 예를 들어 한 칸씩 뒤로 간다거나, 앞으로 두 칸씩 간다거나. 이터레이터를 매개변수로 받는다.

rotate(_FwdIt _First, _FwdIt _Mid, _FwdIt _Last)

사용 예시.

vector<class RunningRect*> objs;
...
rotate(objs.begin(), objs.begin() + 1, objs.end())	// 왼쪽으로 1칸씩 이동.
rotate(objs.begin(), objs.begin() - 1, objs.end())	// 오른쪽으로 1칸씩 이동.

다만 회전시킬 때마다 원소간에 swap이 일어나기 때문에, 원소가 많은 경우에는 비효율적이다.

profile
Question, Think, Select

0개의 댓글