Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ConjuntoTabla implements Conjunto {
- //Descripció general: Implementación en forma de tabla de enteros
- //Tabla de enteros ordenada de forma creciente
- private int tablaInt[];
- public void añadir(int n)
- //Pre: --
- //Post: Se ha añadido n al conjunto ordenadamente
- {
- //No puede contener elementos duplicados
- if (!this.pertenece(n)) {
- int i = this.nelem();
- while (i > 0 && n < this.tablaInt[i-1]) {
- this.tablaInt[i] = this.tablaInt[i-1];
- i--;
- }
- this.tablaInt[i] = n;
- }
- }
- public Conjunto union(Conjunto c) {
- Conjunto union = new ConjuntoTabla();
- for (int i=0; i < this.nelem(); i++) {
- [B] union.tablaInt[i] = this.tablaInt[i];[/B]
- }
- for (int i=0; i < c.nelem(); i++) {
- [B]union.añadir(c.tablaInt[i]);[/B]
- }
- return union;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement