Created
May 27, 2021 10:26
-
-
Save joechai93/ce6ac45ca1abc6cab513e14dafef6481 to your computer and use it in GitHub Desktop.
Cyclic insertion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#include <vector> | |
#include <algorithm> | |
#include <numeric> | |
#include <cmath> | |
int main() | |
{ | |
std::vector<int> v = {1,4,6,3}; | |
int K = 3; | |
int counter = 1; | |
int back_value = v.at(v.size()-1); | |
std::vector<int>::iterator it; | |
while (counter <= K) { | |
back_value = v.at(v.size()-1); | |
it = v.begin(); | |
v.insert(it,back_value); | |
v.pop_back(); | |
counter++; | |
} | |
for (auto i : v ) { | |
std::cout << i << std::endl; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment