C Programming Code Examples C > Recursion Code Examples Program to Implement Selection Sort Recursively Program to Implement Selection Sort Recursively This C Program implements a Selection sort. Selection sort works by finding the smallest unsorted item in the list and swapping it with the item in the current position. It is used for sorting unsorted list of elements. #include <stdio.h> void selection(int [], int, int, int, int); int main() { int list[50], size, temp, x, j; printf("Enter the size of the list: "); scanf("%d", &size); printf("Enter the elements in list:\n"); for (x = 0; x < size; x++) { scanf("%d", &list[x]); } selection(list, 0, 0, size, 1); printf("The sorted list in ascending order is\n"); for (x = 0; x < size; x++) { printf("%d ", list[x]); } return 0; } void selection(int list[], int x, int j, int size, int flag) { int temp; if (x < size - 1) { if (flag) { j = x + 1; } if (j < size) { if (list[x] > list[j]) { temp = list[x]; list[x] = list[j]; list[j] = temp; } selection(list, x, j + 1, size, 0); } selection(list, x + 1, 0, size, 1); } }