Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #define maxSize 10
- void selectSort(int arr[]);
- main()
- {
- int array[maxSize], i = 0;
- while ( !feof(stdin) )
- fscanf(stdin, "%d", &array[++i]);
- array[0] = i;
- printf("\n");
- selectSort(array);
- for (i = 1; i < array[0]; i++)
- printf("%d ", array[i]);
- printf("\n");
- return 0;
- }
- void swap(int *x, int *y)
- {
- int tmp;
- tmp = *x;
- *x = *y;
- *y = tmp;
- return;
- }
- void selectSort(int arr[])
- {
- int i, j, minIndex;
- for (j = 1; j < arr[0]; j++) {
- minIndex = j;
- for (i = j; i < arr[0]; i++) {
- if (arr[i] < arr[minIndex])
- minIndex = i;
- }
- swap(&arr[j], &arr[minIndex]);
- }
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment