1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | public class BubbleSort{ public static void main(String []args){ int[] arr = {3,2,5,4,7,9,1}; for(int i=0; i<=arr.length-2; i++){ boolean flag = false; for(int j=0; j<=arr.length-i-2; j++){ if(arr[j]>arr[j+1]){ int temp = arr[j]; arr[j] = arr[j+1]; arr[j+1] = temp; flag = true; } } if(flag==false) break; } for(int i:arr) System.out.print(i+" "); } } |
Jadaghjkjs
By
Code Heist

No comments:
Post a Comment