This commit is contained in:
2023-11-29 16:08:44 +01:00
parent 446eb575de
commit 4041397b09
56 changed files with 1463 additions and 17 deletions

Binary file not shown.

View File

@@ -0,0 +1,79 @@
import java.util.*;
public class Q1Arbre{
private Q1Noeud racine;
public Q1Arbre(){
this.racine = null;
}
public Q1Arbre(int clef){
this.racine = new Q1Noeud(clef);
}
public Q1Arbre(Q1Noeud racine){
this.racine = racine;
}
public void add(Q1Noeud newNoeud){
if (this.racine == null){
this.racine = newNoeud;
}
else{
this.racine.add(newNoeud);
}
}
public void add(int clef){
if (this.racine == null){
this.racine = new Q1Noeud(clef);
}
else{
this.racine.add(clef);
}
}
private Q1Noeud plusPetit(){
if (this.racine != null){
Q1Noeud minimum = this.racine;
while (minimum.getPetit() != null){
minimum = minimum.getPetit();
}
return minimum;
}
return this.racine;
}
private Q1Noeud plusGrand(){
if (this.racine != null){
Q1Noeud maximum = this.racine;
while (maximum.getPetit() != null){
maximum = maximum.getPetit();
}
return maximum;
}
return this.racine;
}
private Q1Noeud suivant(int clef){
if (this.racine != null){
Q1Noeud maximum = this.racine;
while (maximum.getPetit() != null){
maximum = maximum.getPetit();
}
return maximum;
}
return this.racine;
}
public void affichage(){
if (this.racine != null){
Q1Noeud plusPetit = this.racine;
while (plusPetit.getPetit() != null){
plusPetit = plusPetit.getPetit();
}
System.out.print(plusPetit);
while ()
}
}
}

Binary file not shown.

View File

@@ -0,0 +1,19 @@
import java.util.*;
import java.io.*;
public class Q1Main{
public static void main(String[] args){
try{
Q1Arbre arbre = new Q1Arbre();
for (String arg : args){
int n = Integer.parseInt(arg);
arbre.add(n);
}
arbre.affichage();
}
catch(NumberFormatException e){
System.out.println("NumberFormatException : Veuillez saisir des nombres en arguments");
}
}
}

Binary file not shown.

View File

@@ -0,0 +1,81 @@
import java.util.*;
public class Q1Noeud{
private int clef;
private Q1Noeud petit;
private Q1Noeud grand;
private int occurence;
public Q1Noeud(int clef){
this.clef = clef;
this.petit = null;
this.grand = null;
this.occurence = 1;
}
public int getKey(){
return this.clef;
}
public void add(int fils){
if (fils < this.clef){
if (this.petit == null){
this.petit = new Q1Noeud(fils);
}
else{
this.petit.add(fils);
}
}
if (fils > this.clef){
if (this.grand == null){
this.grand = new Q1Noeud(fils);
}
else{
this.grand.add(fils);
}
}
if (fils == this.clef){
this.occurence ++;
}
}
public void add(Q1Noeud newNoeud){
if (newNoeud.getKey() < this.clef){
if (this.petit == null){
this.petit = newNoeud;
}
else{
this.petit.add(newNoeud);
}
}
if (newNoeud.getKey() > this.clef){
if (this.grand == null){
this.grand = newNoeud;
}
else{
this.grand.add(newNoeud);
}
}
if (newNoeud.getKey() == this.clef){
this.occurence ++;
}
}
public Q1Noeud getPetit(){
return this.petit;
}
public Q1Noeud getGrand(){
return this.grand;
}
@Override
public String toString(){
String resultat = "";
int i;
for (i=0; i<this.occurence; i++){
resultat += (this.clef + " ");
}
return resultat;
}
}