fin tp3
This commit is contained in:
49
DEV3.2/TP03/03_Tableau/CouleurList.java
Normal file
49
DEV3.2/TP03/03_Tableau/CouleurList.java
Normal file
@@ -0,0 +1,49 @@
|
||||
import java.awt.*;
|
||||
import javax.swing.*;
|
||||
import java.util.List;
|
||||
import java.util.Iterator;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class CouleurList<E> implements Iterable<E> {
|
||||
|
||||
protected E[] valeurs;
|
||||
|
||||
public CouleurList() {
|
||||
this.valeurs = (E[]) new Object[10];
|
||||
}
|
||||
|
||||
public CouleurList(E element) {
|
||||
this.valeurs = (E[]) new Object[10];
|
||||
this.valeurs[0] = element;
|
||||
}
|
||||
|
||||
public void add(E element) {
|
||||
for (int i = 0; i != this.valeurs.length; i++) {
|
||||
if (this.valeurs[i] == null) {
|
||||
this.valeurs[i] = element;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean remove(E element) {
|
||||
for (int i = 0; i != this.valeurs.length; i++) {
|
||||
if (this.valeurs[i] != null && this.valeurs[i].equals(element)) {
|
||||
for (int j = i; j != this.valeurs.length-1; j++) {
|
||||
this.valeurs[j] = this.valeurs[j+1];
|
||||
}
|
||||
this.valeurs[this.valeurs.length - 1] = null;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<E> iterator() {
|
||||
return new Iterateur(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user