Advertisement
Guest User

Untitled

a guest
Jan 24th, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class ccc5s2 {
  3. public static void main(String[] args) {
  4. Scanner sc= new Scanner(System.in);
  5. // compare with neighbor and see if A[i]<A[i+1]
  6. // 2 1 3
  7. // 2 3 1
  8. // 3 2 1
  9. int count = 0;
  10. int N = sc.nextInt();
  11. int[] A = new int[N];
  12. while (true) { //repeat multiple times
  13. boolean isSwap = false; //never swap yet
  14. for (int i=1; i<N; i++) {
  15. if (A[i-1]<A[i]) {
  16. //swap
  17. int temp = A[i];
  18. A[i] = A[i-1];
  19. A[i-1] = temp;
  20. count++;
  21. isSwap = true;
  22. }
  23. }
  24. if (isSwap==false) {
  25. break;
  26. }
  27. }
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement