Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package testing;
- import java.util.Scanner;
- public class TritochkaTri {
- public static void insertionSort(int arr[]) {
- int n = arr.length;
- for (int j = 1; j < n; j++) {
- int key = arr[j];
- int i = j - 1;
- while ((i > -1) && (arr[i] > key)) {
- arr[i + 1] = arr[i];
- i--;
- }
- arr[i + 1] = key;
- }
- }
- public static void main(String[] args) {
- int[] arr1 = {1, -4, 32, -5};
- System.out.println("Before Insertion Sort:");
- for (int i : arr1) {
- System.out.print(i + " ");
- }
- System.out.println();
- insertionSort(arr1);
- System.out.println("After Insertion Sort:");
- for (int i : arr1) {
- System.out.print(i + " ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement