/ Published in: C
Expand |
Embed | Plain Text
#include <stdio.h> void swap(int *x, int *y) { int temp; temp = *x; *x = *y; *y = temp; } void selectionSort(int list[], int n) { int i, j, min; for (i = 0; i < n - 1; i++) { min = i; for (j = i + 1; j < n; j++) { if (list[j] < list[min]) { min = j; } } swap(&list[i], &list[min]); } } void printList(int list[], int n) { int i; for (i = 0; i < n; i++) { if (i < n - 1) else } } void main() { const int MAX = 30; int list[MAX]; int i; i = 0; for (i = 0; i < MAX; i++) { scanf("%d", &list[i]); } // print the input printList(list, MAX); // sort an array selectionSort(list, MAX); // print the output printList(list, MAX); }
You need to login to post a comment.
