Exchange sort
import java.util.*;
public class ExchangeSort
{
public static void main(String[] args)
{
int[] array;
int i, j, temp, size;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the size of array");//Introduzca el tamaño de la matriz
size = sc.nextInt();
array = new int[size];
System.out.println("Enter the elements of array : "); //Introduzca los elementos de la matriz
for (i = 0; i < size; i++)
{
array[i] = sc.nextInt();
}
//Exchange sort , ordenacion de intercambio
for (i = 0; i < (size - 1); i++)
{
for (j = (i + 1); j < size; j++)
{
if (array[i] > array[j])
{
temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
}
System.out.println("Sorted Array is : "); //el vector ordenado es
for (i = 0; i < size; i++)
{
System.out.print(array[i] + " ");
}
}
}
--------------------Configuration: <Default>--------------------
Enter the size of array
3
Enter the elements of array :
2
5
7
Sorted Array is :
2 5 7
Process completed.
No hay comentarios:
Publicar un comentario