Skip to content

Instantly share code, notes, and snippets.

@uncoded-ro
Created January 12, 2020 13:59
Show Gist options
  • Save uncoded-ro/1ca2e7753c24c620d554a14f9c2dbf9a to your computer and use it in GitHub Desktop.
Save uncoded-ro/1ca2e7753c24c620d554a14f9c2dbf9a to your computer and use it in GitHub Desktop.
class Sortare {
public static void sortare(int[] numere) {
for (int i = 0; i < numere.length; i++) {
int min = i;
for (int j = i; j < numere.length; j++) {
if (numere[j] < numere[min])
min = j;
}
int temp;
temp = numere[i];
numere[i] = numere[min];
numere[min] = temp;
}
}
public static void main(String[] args) {
int[] numere = new int[10];
for (int i = 0; i < numere.length; i++) {
numere[i] = (int) (Math.random() * 100);
}
System.out.println("Afisare elemente tablou inainte de sortare");
for (int i = 0; i < numere.length; i++) {
System.out.print(numere[i] + " ");
}
sortare(numere);
System.out.println();
System.out.println("Afisare elemente tablou dupa sortare");
for (int i = 0; i < numere.length; i++) {
System.out.print(numere[i] + " ");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment