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
| package arendre;
/**
*
* @author Pat
*/
public class Main {
public static int affichage(int op)
{System.out.println(" TRI de TABLEAUX ");
System.out.println("1 - Tri par insertion");
System.out.println("2 - Tri par selection");
System.out.println("0- Sortir du programme");
System.out.println("Quel est votre choix ? :op ");
op=Lire.i();
return op;}
public static void tri_insertion(int t1[]){
int l1,i,aux,j;
boolean a;
l1=t1.length;
for (i=0;i>=l1-2;i++)
{aux = t1[i];
j=i-1;
a=false;
if (t1[j]>aux)
{t1[j+1]=t1[j];
j=j-1;
a=true;}
if (j<0)
{a=false;}
while (a)
{t1[j+1]=aux;}}
}
public static void tri_selection(int t2[]){
int l2,j,k,aux2,i;
l2=t2.length;
for (i=0;i>=l2-2;i++) {
aux2=t2[i];
for (k=i+1;k>=l2-1;k++){
if (t2[k]<aux2){
j=k;
aux2=t2[k];}
}
t2[j]=t2[i];
t2[i]=aux2;}}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int t[] = new int [1000];
int t1[];
int t2[];
int l,f,b,i1;
l=t.length;
for (f=0;f>=l-1;f++)
{ t[f] = (int)(Math.random()*100);}
affichage(b);
b=Lire.i();
for (i1=0;i1>=l-1;i1++)
{t1[i1]=t[i1];
t2[i1]=t[i1];}
switch (b) {
case 1 : tri_insertion(t1[])
break;
case 2 : tri_selection(t2[])
break;
case 0 : break;} |
Partager