Advertisement
Guest User

Untitled

a guest
Sep 7th, 2016
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.69 KB | None | 0 0
  1. void sort(int values[], int n)
  2. {
  3.     //The values in the array are checked from left to right
  4.     //starting from the second one
  5.     //The current value is stored and a second index is created
  6.     for(int i = 1; i < n; i++)
  7.     {
  8.         int valueToInsert = values[i];
  9.         int j = i-1;
  10.        
  11.         while((j >= 0) && (valueToInsert < values[j]))
  12.         {
  13.         //Keep shifting the hole down until while the stored value
  14.         //is less than the value being checked
  15.             values[j+1] = values[j];
  16.             j --;
  17.         }
  18.    
  19.     //The hole is now in its correct position, so insert the stored value
  20.     values[j+1] = valueToInsert;
  21.     }
  22.  
  23.     return;
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement