Skip to content

Instantly share code, notes, and snippets.

@TakashiHarada
Last active August 29, 2015 14:27
Show Gist options
  • Save TakashiHarada/b5b4eac372bcee481ae6 to your computer and use it in GitHub Desktop.
Save TakashiHarada/b5b4eac372bcee481ae6 to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
using namespace std;
void f(vector<int> *p)
{
vector<int>::iterator it = p->begin();
int i = 0;
int max = 0;
while (i < p->size())
{
if ((*p)[i] > i)
{
int l = (*p)[i];
p->insert(it, (*p)[i]-max, -1);
it = p->begin();
for (int k = 0; k < i; ++k)
{
++it;
}
}
if ((*p)[i] != -1)
{
max = (*p)[i]+1;
}
++i;
++it;
}
}
int main()
{
vector<int> *vp = new vector<int>;
//vp->push_back(0);
//vp->push_back(1);
vp->push_back(2);
//vp->push_back(3);
//vp->push_back(4);
vp->push_back(5);
f(vp);
vector<int>::iterator vit, vit_end;
vit = vp->begin(), vit_end = vp->end();
while (vit != vit_end)
{
cout << *vit << endl;
++vit;
}
delete vp;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment