Created
January 24, 2015 15:56
-
-
Save erseco/20638ecbe53d5ba197c0 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
// Dadas 2 colas con elementos repetidos (y ordenados) implementar la función queue<int> multiinterseccion (queue<int> q1, queue<int> q2) que calcule la multi intersección de 2 colas que y q2 y devuelva el resultado en otra cola. | |
// q1=[2,2,3,3] | |
// q2=[1,2,3,3,4] | |
// multi intersección=[2,3,3] | |
queue<int> multiinterseccion (queue<int> q1, queue<int> q2) | |
{ | |
queue<int> multi, q2aux; | |
while(!q1.empty()) | |
{ | |
bool aparece_en_ambas = false; | |
while (!q2.empty()) | |
{ | |
if (q1.front() == q2.front() ) | |
aparece_en_ambas = true; | |
else | |
q2aux.push(q2.front()); | |
q2.pop(); | |
} | |
if (aparece_en_ambas) | |
multi.push(q1.front()); | |
q2 = q2aux; | |
q1.pop(); | |
} | |
return multi; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment