devLupin / algorithm

PS
1 stars 0 forks source link

rotate in <algorithm> #27

Open devLupin opened 1 year ago

devLupin commented 1 year ago

rotate

usage

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    vector<int> v = { 10, 40, 50, 30, 20 };

    cout << "vector : ";
    for (int i : v) cout << i << " ";
    cout << "\n================================\n";

    rotate(v.begin(), v.begin() + 1, v.end());
    cout << "1칸씩 왼쪽 이동 : ";
    for (int i : v) cout << i << " ";
    cout << "\n================================\n";

    rotate(v.begin(), v.end() - 1 , v.end());
    cout << "1칸씩 오른쪽 이동 : ";
    for (int i : v) cout << i << " ";
    cout << "\n================================\n";

    return 0;
}
devLupin commented 1 year ago

관련 문제 및 내가 작성한 코드