Last active
December 12, 2021 17:30
-
-
Save sunmeat/f92e28fc4a48faf3b2fb to your computer and use it in GitHub Desktop.
bubble sort example for android 8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.alex.sorting; | |
public class JavaApplication1 { | |
public static void main(String[] args) { | |
int size = 10; | |
int ar[] = new int[size]; | |
// before sort | |
for (int i = 0; i < size; i++) { | |
ar[i] = (int) (Math.random() * 100); | |
System.out.print(ar[i] + " "); | |
} | |
System.out.print("\n\n"); | |
// start sort | |
for (int pr = 0; pr < size - 1; pr++) { | |
for (int i = size - 1; i > 0; i--) { | |
if (ar[i - 1] > ar[i]) { | |
int temp = ar[i - 1]; | |
ar[i - 1] = ar[i]; | |
ar[i] = temp; | |
} | |
} | |
} | |
// after sort | |
for (int i = 0; i < size; i++) { | |
System.out.print(ar[i] + " "); | |
} | |
System.out.print("\n\n"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment