Ajout des fichier exo 0

This commit is contained in:
2025-12-03 13:33:24 +01:00
parent 04711160ad
commit aa1e9ab878
4 changed files with 93 additions and 0 deletions
+3
View File
@@ -0,0 +1,3 @@
public enum Base {
A, T, C, G;
}
+21
View File
@@ -0,0 +1,21 @@
public class Exemple {
public static void main(String[] args) {
MonBrin brin = new MonBrin();
brin.ajouterFin(Base.G);
brin.ajouterFin(Base.C);
brin.ajouterFin(Base.T);
brin.ajouterFin(Base.T);
brin.ajouterFin(Base.A);
brin.ajouterFin(Base.G);
System.out.println(brin); // gcttag
Iterator<Base> it = brin.iterator();
while(it.hasNext()) {
System.out.println(it.next());
}
}
}
+48
View File
@@ -0,0 +1,48 @@
public class MonBrin {
private MonMaillon head;
public MonBrin() {
this.head = null;
}
// Ajouter une base au début du brin
public void ajouterDebut(Base b) {
head = new MonMaillon(b, head);
}
// Ajouter une base à la fin du brin
public void ajouterFin(Base b) {
if (head == null) {
head = new MonMaillon(b, null);
return;
}
MonMaillon courant = head;
while (courant.getNext() != null) {
courant = courant.getNext();
}
courant.setNext(new MonMaillon(b, null));
}
public MonMaillon getHead() {
return head;
}
// Fournir un itérateur maison
public Iterator<Base> iterator() {
return new MonBrinIterator(this.head);
}
// Pour affichage du brin entier
@Override
public String toString() {
String s = "";
MonMaillon courant = head;
while (courant != null) {
s += courant.getBase().toString();
courant = courant.getNext();
}
return s.toLowerCase(); // affiche : gcttag
}
}
+21
View File
@@ -0,0 +1,21 @@
public class MonMaillon {
private Base base;
private MonMaillon next;
public MonMaillon(Base b, MonMaillon suivant) {
this.base = b;
this.next = suivant;
}
public Base getBase() {
return base;
}
public MonMaillon getNext() {
return next;
}
public void setNext(MonMaillon n) {
this.next = n;
}
}