Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void sort(int values[], int n)
- {
- //The values in the array are checked from left to right
- //starting from the second one
- //The current value is stored and a second index is created
- for(int i = 1; i < n; i++)
- {
- int valueToInsert = values[i];
- int j = i-1;
- while((j >= 0) && (valueToInsert < values[j]))
- {
- //Keep shifting the hole down until while the stored value
- //is less than the value being checked
- values[j+1] = values[j];
- j --;
- }
- //The hole is now in its correct position, so insert the stored value
- values[j+1] = valueToInsert;
- }
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement