Last active
August 29, 2015 14:14
-
-
Save erseco/5b18fd485e7d3d49402d to your computer and use it in GitHub Desktop.
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
// Diseñar una función que dada una lista L devuelva otra lista R conteniendo los elementos repetidos de L. Si no hay elementos repetidos R será la lista vacía. | |
// L = [5, 2, 7, 2, 5, 1] | |
// R = [5, 2] | |
list<int> repetidos(list<int> L) | |
{ | |
list<int> R; | |
for (list<int>::iterator it1 = L.begin(); it1!=L.end(); ++it1) | |
for (list<int>::iterator it2 = L.begin(); it2!=L.end(); ++it2) | |
if (it1!=it2 && *it1==*it2) | |
{ | |
R.push_back(*it1); | |
L.erase(it1); // lo borramos de la lista | |
} | |
return R; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Diseñar una función que dada una lista L devuelva otra lista R conteniendo los elementos repetidos de L. Si no hay elementos repetidos R será la lista vacía.