Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 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. }
  14.  
  15. for i ← 1 to length(A)
  16. j ← i
  17. while j > 0 and A[j-1] > A[j]
  18. swap A[j] and A[j-1]
  19. j ← j - 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement