Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class TestWork {
- public static void main(String[] args) {
- int[] x = {2, 64, 12, 123, 92, 3, 14};
- for(int a:insertionSort(x)){
- System.out.println(a);
- }
- }
- public static int[] insertionSort(int[] x){
- int valueToInsert;
- int holePosition;
- for (int i=1; i<x.length;i++){
- valueToInsert = x[i];
- holePosition = i;
- while( (holePosition > 0) && (x[holePosition-1] > valueToInsert)){
- x[holePosition] = x[holePosition-1];
- holePosition = holePosition -1;
- }
- x[holePosition] = valueToInsert;
- }
- return x;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement