Hello,
I really am blocked now... I can't figure out the algorith to inverse the contects of a table... and I have been working on it for quite a while now but I don't get decent results..
here's my code
class Table{
int contenu[];
int taille;
Table(){
System.out.println("quelle est la taille du tableau à créer");
taille = Clavier.lireInt();
contenu = new int[taille];
initValue();
}
Table(int n){
taille = n;
contenu = new int[taille];
initValue();
}
private void initValue(){
System.out.println("valeur de chacune des cases");
for(int i=0;i<taille;i++){
contenu[i]= Clavier.lireInt();
}
}
// fonction d'affichage
public String toString(){
String s="[";
for(int i=0;i<taille-1;i++)
s=s+contenu[i]+",";
s=s+contenu[taille-1]+"]";
return(s);
}
public void reverse(){
int tab2[]= new int[taille];
for(int i = taille-1; i>=0;i--){
int k =0 ;
tab2[k] = contenu[i];
k++;
}
for (int i=0;i<taille;i++){
contenu[i]= tab2[i];
}
}
public void sort(){
int j;
for(int i=1;i<taille;i++){
for(j=0;contenu[j]<contenu[i];j++);
int tampon = contenu[i];
for (int k=i;k>j;k--)
contenu[k] = contenu[k-1];
contenu[j] = tampon;
}
}
}
public class Tableau{
public static void main(String args[]){
Table tab = new Table(5);
tab.sort();
System.out.println( "tableau trié " + tab);
Table tab1 = new Table();
System.out.println("tableau non inverse " +tab1);
tab1.reverse();
System.out.println("tableau inversé " +tab1);
}
} some of it it's in french but it really doens't matter.. I just need to know why my code of public void reverse() doesn't work... and how should I proceed to debug the program..
thanks in advance,
Mario