Home Lifestyle Selection Sort program in C Language

# Selection Sort program in C Language

46
0 Selection Sort program in C Language algorithm implementation – selection sort is it never makes more than O(n) swaps and can be useful when memory write is a costly operation.

• Time Complexity: O(n2)
• Auxiliary Space: O(1)

In this program user would be asked to enter the number of elements along with the element values and then the programs would sort them in ascending order by using merge sorting algorithm logic.

## Selection Sort algorithm C Program implementation

``````

#include <stdio.h>
int main() {
int arr={5,11,1,19,12,100,56,46,35,3};
int n=10;
int i, j, position, swap;
for (i = 0; i < (n - 1); i++) {
position = i;
for (j = i + 1; j < n; j++) {
if (arr[position] > arr[j])
position = j;
}
if (position != i) {
swap = arr[i];
arr[i] = arr[position];
arr[position] = swap;
}
}
for (i = 0; i < n; i++)
printf("%d\t", arr[i]);
return 0;
}

``````

## OUTPUT

``````

1 3 7 12 13 19 35 46 56 100

``````