Skip to content

Instantly share code, notes, and snippets.

@joechai93
Created May 27, 2021 10:26
Show Gist options
  • Save joechai93/ce6ac45ca1abc6cab513e14dafef6481 to your computer and use it in GitHub Desktop.
Save joechai93/ce6ac45ca1abc6cab513e14dafef6481 to your computer and use it in GitHub Desktop.
Cyclic insertion
#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