Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Problem : Introduction to Insertion Sorting.
- // AUTHOR : fueanta
- // Written : 14-Oct-16
- #include "cstdio"
- void ins_sort(int *, int);
- void main() {
- int arr[] = { 5, 3, 7, 2, 4, 5, 1 };
- printf("\n"); ins_sort(arr, (sizeof(arr) / 4));
- for (int i = 0; i < (sizeof(arr) / 4); i++) {
- printf("|%d|", arr[i]);
- }
- printf("\n\n");
- }
- void ins_sort(int arr[], int n) {
- for (int i = 1; i <= n - 1; i++) {
- int LOC = i;
- int VAL = arr[LOC];
- while (LOC > 0 && arr[LOC - 1] > VAL) {
- arr[LOC] = arr[LOC - 1];
- LOC--;
- }
- arr[LOC] = VAL;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment