Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- void PrintArray(int *Start, int Number);
- int main(int argc, char *argv[])
- {
- if (argc == 1)
- {
- printf("Please give me a space seperated list of numbers to sort!\n");
- return 1;
- }
- argc--;
- int SortMe[1024], i;
- for (i = 0; i < argc - 1; i++)
- SortMe[i] = atoi(argv[i + 1]);
- for (i = 1; i < argc; i++)
- {
- int Current = SortMe[i];
- int j;
- for (j = i - 1; j != -1 && SortMe[j] > Current; j--)
- SortMe[j + 1] = SortMe[j];
- SortMe[j + 1] = Current;
- PrintArray(SortMe, argc);
- }
- return 0;
- }
- void PrintArray(int *Start, int Number)
- {
- int i;
- for (i = 0; i < Number; i++)
- printf("%d, ", *(Start + i));
- printf("\n");
- }
- /*
- abdul@computer [~/Programming/InsertionSort]:
- gcc InsertionSort.c -g -Wall -o InsertionSort
- abdul@computer [~/Programming/InsertionSort]:
- ./InsertionSort 4 2 8 5 3 8 9 3
- 0, 2, 8, 5, 3, 8, 9, 3,
- 0, 2, 8, 5, 3, 8, 9, 3,
- 0, 2, 5, 8, 3, 8, 9, 3,
- 0, 2, 3, 5, 8, 8, 9, 3,
- 0, 2, 3, 5, 8, 8, 9, 3,
- 0, 2, 3, 5, 8, 8, 9, 3,
- 0, 2, 3, 3, 5, 8, 8, 9,
- */
Advertisement
Add Comment
Please, Sign In to add comment