Advertisement
Guest User

Untitled

a guest
Feb 15th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. public class ConjuntoTabla implements Conjunto {
  2. //Descripció general: Implementación en forma de tabla de enteros
  3.  
  4. //Tabla de enteros ordenada de forma creciente
  5. private int tablaInt[];
  6.  
  7. public void añadir(int n)
  8. //Pre: --
  9. //Post: Se ha añadido n al conjunto ordenadamente
  10. {
  11. //No puede contener elementos duplicados
  12. if (!this.pertenece(n)) {
  13. int i = this.nelem();
  14. while (i > 0 && n < this.tablaInt[i-1]) {
  15. this.tablaInt[i] = this.tablaInt[i-1];
  16. i--;
  17. }
  18. this.tablaInt[i] = n;
  19. }
  20. }
  21.  
  22.  
  23. public Conjunto union(Conjunto c) {
  24. Conjunto union = new ConjuntoTabla();
  25. for (int i=0; i < this.nelem(); i++) {
  26. [B] union.tablaInt[i] = this.tablaInt[i];[/B]
  27. }
  28. for (int i=0; i < c.nelem(); i++) {
  29. [B]union.añadir(c.tablaInt[i]);[/B]
  30. }
  31. return union;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement