In this program, we are going to share a C program to implement selection sort recursively. If you are a beginner and want to start learning the C programming, then keep your close attention in this tutorial as I am going to share a C program to implement selection sort recursively with the output.
We have designed this program for beginners for learning purpose. Copy below c program and execute it with c compiler to see the output of the program.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
#include <stdio.h> void selection(int [], int, int, int, int); int main() { int list[30], size, temp, i, j; printf("Enter the size of the list: "); scanf("%d", &size); printf("Enter the elements in list:\n"); for (i = 0; i < size; i++) { scanf("%d", &list[i]); } selection(list, 0, 0, size, 1); printf("The sorted list in ascending order is\n"); for (i = 0; i < size; i++) { printf("%d ", list[i]); } return 0; } void selection(int list[], int i, int j, int size, int flag) { int temp; if (i < size - 1) { if (flag) { j = i + 1; } if (j < size) { if (list[i] > list[j]) { temp = list[i]; list[i] = list[j]; list[j] = temp; } selection(list, i, j + 1, size, 0); } selection(list, i + 1, 0, size, 1); } } |
Enter the size of the list: 5
Enter the elements in list:
90
60
110
123
10
The sorted list in ascending order is
10 60 90 110 123
Liked this program? Do Like & share with your friends.
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.