Last active
August 29, 2015 14:28
-
-
Save TakashiHarada/d8ff0bb50c3aed546f68 to your computer and use it in GitHub Desktop.
This file contains 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 <bits/stdc++.h> | |
using namespace std; | |
void f(vector<int> *v) | |
{ | |
vector<int>::iterator vit, vit_end; | |
vector<int>::iterator vit2, vit2_end; | |
vit = v->begin(); | |
int i = 0; | |
int j; | |
while (i < v->size()) | |
{ | |
vit2 = vit; | |
++vit2; | |
j = i + 1; | |
while (j < v->size()) | |
{ | |
if (*vit == *vit2) | |
{ | |
//cout << &(*vit2) << ' ' << *vit2 << endl; | |
vit2 = v->erase(vit2); | |
--j; | |
--vit2; | |
//cout << *vit2 << endl; | |
} | |
++j; | |
++vit2; | |
} | |
++i; | |
++vit; | |
} | |
} | |
int main() | |
{ | |
vector<int> *v = new vector<int>; | |
for (int i = 0; i < 7; ++i) | |
{ | |
v->push_back(i); | |
} | |
v->push_back(0); | |
v->push_back(9); | |
v->push_back(0); | |
v->push_back(0); | |
v->push_back(0); | |
v->push_back(0); | |
v->push_back(0); | |
vector<int>::iterator vit, vit_end; | |
vit = v->begin(), vit_end = v->end(); | |
while (vit != vit_end) | |
{ | |
cout << &(*vit) << ' ' << *vit << endl; | |
++vit; | |
} | |
printf("=========\n"); | |
f(v); | |
//printf("=========\n"); | |
vit = v->begin(), vit_end = v->end(); | |
while (vit != vit_end) | |
{ | |
cout << &(*vit) << ' ' << *vit << endl; | |
++vit; | |
} | |
delete v; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment