Advertisement
rsvaco

PRG Pract 5 - interseccion

May 26th, 2017
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. public ConjuntoString interseccion(ConjuntoString otro) {
  2. ConjuntoString result = new ConjuntoString();
  3. NodoString aux1 = this.primero; // nodo a revisar del conjunto this
  4. NodoString aux2 = otro.primero; // nodo a revisar de otro
  5. NodoString ultResult = null; // último nodo de result, inicialmente null
  6. boolean killSwitch = false;
  7. while (aux1 != null && aux2 != null) {
  8. if(aux1.dato.compareTo(aux2.dato) == 0){
  9. if(killSwitch == false){
  10. result.primero = new NodoString(aux1.dato);
  11. ultResult = result.primero;
  12.  
  13. killSwitch = true;
  14. } else {
  15. ultResult.siguiente = new NodoString(aux1.dato);
  16. ultResult = ultResult.siguiente;
  17.  
  18.  
  19. }
  20. aux1 = aux1.siguiente;
  21. aux2= aux2.siguiente;
  22. result.talla++;
  23. } else {
  24. if(aux1.dato.compareTo(aux2.dato) < 0){
  25. aux1 = aux1.siguiente;
  26. } else if(aux1.dato.compareTo(aux2.dato) > 0){
  27. aux2 = aux2.siguiente;
  28. }
  29. }
  30. }
  31. return result;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement