1
을 통해 배열을 인쇄하는 중 메신저는 각 패스 후에 배열을 인쇄 할 방법을 찾고 있습니다. 이것은 내가 지금까지 가지고있는 정렬 코드입니다. 어레이의 원래 상태와 분류 상태각 패스 (Bubble Sort)
public class bubbleSortTest
{
public static void main(String a[])
{
int i;
int array[] = {90, 8, 7, 56, 123, 235, 9, 1, 653};
System.out.println("Values Before the sort:\n");
for(i = 0; i < array.length; i++)
System.out.print(array[i]+" ");
System.out.println();
bubble_srt(array, array.length);
System.out.print("Values after the sort:\n");
for(i = 0; i <array.length; i++)
System.out.print(array[i]+" ");
System.out.println();
System.out.println("PAUSE");
}
public static void bubble_srt(int a[], int n)
{
int i, j,t=0;
for(i = 0; i < n; i++)
{
for(j = 1; j < (n-i); j++)
{
if(a[j-1] > a[j])
{
t = a[j-1];
a[j-1]=a[j];
a[j]=t;
}
}
}
}
}
내부 루프에 '교환'이 없으면 목록이 정렬되었음을 나타냅니다. 따라서 프로세스 정렬을 중단 할 수 있습니다. 다양한 정렬 알고리즘은 다음을 참조하십시오. http://www.sorting-algorithms.com/bubble-sort –