Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. #include "insertionSort.hpp"
  2.  
  3.  
  4. void insertionSort(int A[], int n){
  5.  
  6. int i = 0;
  7. int j = 0;
  8. int temp = 0; // Temporary variable for swap
  9.  
  10. for (i = 1; i < n; ++i) {
  11. j = i;
  12. // Insert numbers[i] into sorted part
  13. // stopping once numbers[i] in correct position
  14. while (j > 0 && A[j] < A[j - 1]) {
  15.  
  16. // Swap numbers[j] and numbers[j - 1]
  17. temp = A[j];
  18. A[j] = A[j - 1];
  19. A[j - 1] = temp;
  20. --j;
  21. }//end of while
  22. }//end of for
  23. }//end of insertionSort
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement