81 lines
1.8 KiB
Java
81 lines
1.8 KiB
Java
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;
|
|
}
|
|
} |