1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
*********************************************************
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package projet;
import java.io.*;
/**
*
* @author Administrateur
*/
public class fichierselect3 {
public static void fichier (int taille, int d,int an) throws IOException
{
File fichier = new File("C:\\tri-select-anti-trie.txt") ;
BufferedWriter out = new BufferedWriter(new FileWriter(fichier, true));
String c = String.valueOf(d);
String h = String.valueOf(an);
String t = String.valueOf(taille);
out.write(t+" "+c+" "+h);
out.newLine();
out.close() ;
}
public static int[] antitri(int T[],int taille)
{
for (int i=1; i<=taille;i++)
{ T[i-1]= taille-i;}
return(T);}
public static int[] triparselection (int [] T ,int taille) throws IOException {
int k=0,inter,pp;
int cn =0;
int j;
int an=0;
for( j=0;j<=taille-1;j++)
{
pp=j;
for(int i=j+1;i<=taille;i++)
{cn++;
if(T[i]<T[pp])
{pp=i;}
if (pp!=j)
{an++;
inter=T[j];
T[j]=pp;
T[k]=inter; }
}
}
for(int f=0;f<taille;f++)
{
System.out.print(T[f]+" ");
}
System.out.print("\n");
fichier (taille, cn,an);
return T ;
}
public static void main (String []args) throws IOException
{
int i ;
for (i=2;i<=512;i++){
int []T=new int [i];
antitri( T,i );
triparselection (T,i);}
}
} |
Partager