Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. // Sort an array using a simple insertion sort.
  2. public void insertionSort(int[] data) {
  3. for (int which = 1; which < data.length; ++which) {
  4. int val = data[which];
  5. for (int i = 0; i < which; ++i) {
  6. if (data[i] > val) {
  7. System.arraycopy(data, i, data, i + 1, which - i);
  8. data[i] = val;
  9. break;
  10. }
  11. }
  12. }
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement