dhgfhuje
This commit is contained in:
BIN
DEV/DEV3.2/TP08_Arbres_suite/Q1Arbre.class
Normal file
BIN
DEV/DEV3.2/TP08_Arbres_suite/Q1Arbre.class
Normal file
Binary file not shown.
79
DEV/DEV3.2/TP08_Arbres_suite/Q1Arbre.java
Normal file
79
DEV/DEV3.2/TP08_Arbres_suite/Q1Arbre.java
Normal 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 ()
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
DEV/DEV3.2/TP08_Arbres_suite/Q1Main.class
Normal file
BIN
DEV/DEV3.2/TP08_Arbres_suite/Q1Main.class
Normal file
Binary file not shown.
19
DEV/DEV3.2/TP08_Arbres_suite/Q1Main.java
Normal file
19
DEV/DEV3.2/TP08_Arbres_suite/Q1Main.java
Normal 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");
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
DEV/DEV3.2/TP08_Arbres_suite/Q1Noeud.class
Normal file
BIN
DEV/DEV3.2/TP08_Arbres_suite/Q1Noeud.class
Normal file
Binary file not shown.
81
DEV/DEV3.2/TP08_Arbres_suite/Q1Noeud.java
Normal file
81
DEV/DEV3.2/TP08_Arbres_suite/Q1Noeud.java
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user