Skip to content

Instantly share code, notes, and snippets.

@lifeparticle
Last active June 1, 2021 15:15
Show Gist options
  • Save lifeparticle/7fba472236dfc63db76719340abdc967 to your computer and use it in GitHub Desktop.
Save lifeparticle/7fba472236dfc63db76719340abdc967 to your computer and use it in GitHub Desktop.
public class Main {
public static void main (String args[]) {
insertionSort(new int [] {1, 4, 7, 10, 2});
}
public static void insertionSort(int[] arr) {
int tmp, j;
for (int i = 1; i < arr.length; ++i) {
j = i;
while(j > 0 && arr[j] < arr[j-1]) {
tmp = arr [j];
arr [j] = arr [j-1];
arr [j-1] = tmp;
j--;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment