Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package insertion;
- /**
- *
- * @author xxrvnge
- */
- public class Insertion {
- public static void Insertion(int array[]) {
- int n = array.length;
- for (int j = 1; j < n; j++) {
- int key = array[j];
- int i = j-1;
- while ( (i > -1) && ( array [i] > key ) ) {
- array [i+1] = array [i];
- i--;
- }
- array[i+1] = key;
- }
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- // TODO code application logic here
- int[] arr1 = {17,10,13,15,18,12,14,16};
- System.out.println("Sebelum Insertion Sort");
- for(int i:arr1){
- System.out.print(i+" ");
- }
- System.out.println();
- Insertion(arr1);//sorting array using insertion sort
- System.out.println("Sesudah Insertion Sort");
- for(int i:arr1){
- System.out.print(i+" ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement