Sotowanie indeksowe

Kolejna z metod sortowania, cóż więcej można powiedzieć.

class SortowanieInne {
public static void main(String [] args){
int a,max,m,l, licznik,d, k, pomocnicza, s;
k =1;
int j=0;
a = (int)(Math.random () *20);
System.out.println ("Wygenerowana liczba to " +a);
int sort [] = new int [a];
for (int i=0;i<sort.length;i++)
sort[i]=(int)(Math.random()*50);
System.out.println("Elementy Tablicy");
for (int i=0;i<sort.length;i++)
{
System.out.print(sort[i]);
System.out.print(",");
}
System.out.println();
//Wyszukiwanie elementu największego

//sortowanie indeksowe
for (l=0; l<a; l++){
max=sort[0];
m=0;
//pętla wewnętrzna
for(j=0;j<a-l;j++){
if(sort[j]>max) {
max=sort[j];
m=j;
}
}
//zamiana elementów
sort[m]=sort[a-l-1];
sort[a-l-1]=max;
}
System.out.println();
System.out.println("ELEMENTY TABLICY PO POSORTOWANIU");
// wyświetlenie
for(int y=0;y<a;y++)
{
System.out.print(sort[y]);
System.out.print(",");
}
System.out.println();

}
}
download