Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Sort an array using a simple insertion sort.
- public void insertionSort(int[] data) {
- for (int which = 1; which < data.length; ++which) {
- int val = data[which];
- for (int i = 0; i < which; ++i) {
- if (data[i] > val) {
- System.arraycopy(data, i, data, i + 1, which - i);
- data[i] = val;
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement