Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "insertionSort.hpp"
- void insertionSort(int A[], int n){
- int i = 0;
- int j = 0;
- int temp = 0; // Temporary variable for swap
- for (i = 1; i < n; ++i) {
- j = i;
- // Insert numbers[i] into sorted part
- // stopping once numbers[i] in correct position
- while (j > 0 && A[j] < A[j - 1]) {
- // Swap numbers[j] and numbers[j - 1]
- temp = A[j];
- A[j] = A[j - 1];
- A[j - 1] = temp;
- --j;
- }//end of while
- }//end of for
- }//end of insertionSort
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement