✔ 내 답 -> 정답->강의랑 답 같음
그림 출처: https://gmlwjd9405.github.io/2018/05/06/algorithm-bubble-sort.html
import java.util.*;
public class Main{
public static int[] solution(int n, int[] arr){
for(int i=0;i<=n-2;i++) {
for(int j=0;j<=n-2-i;j++){
if(arr[j]>arr[j+1]) {
int tmp = arr[j];
arr[j]=arr[j+1];
arr[j+1]=tmp;
}
}
}
return arr;
}
public static void main(String[] args){
Scanner kb = new Scanner(System.in);
int n = kb.nextInt();
int[] arr = new int[n];
for(int i=0;i<n;i++) arr[i]=kb.nextInt();
for(int x : solution(n,arr)) System.out.print(x+" ");
}
}