Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Main {
- public static void main(String[] args) {
- int[] intArray = {80, 57, 121, 26, 93, 172, 107, 36, 88, 64, 67, 124, 7, 20, 53, 154, 196, 29, 82, 34, 142, 110,
- 159, 17, 192, 46, 65, 115, 162, 184, 168, 102, 35, 19, 23, 70, 163, 166, 187, 129, 90, 193, 143, 167,
- 119, 95, 89, 58, 178, 71};
- insertionSort(intArray);
- }
- public static void insertionSort(int[] data) {
- int n = data.length;
- for (int k = 1; k < n; k++) {
- int cur = data[k];
- int j = k;
- while (j > 0 && data[j - 1] > cur) {
- data[j] = data[j - 1];
- j--;
- }
- data[j] = cur;
- }
- String result = "";
- for (int i : data)
- result += "" + i + " ";
- System.out.println(result);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement