diff --git a/Selection b/Selection new file mode 100644 index 0000000..e0472ae --- /dev/null +++ b/Selection @@ -0,0 +1,36 @@ +#include +void selectionSort(int arr[], int size) { + for (int i = 0; i < size - 1; i++) { + int min_index = i; + // Find the index of the minimum element in the remaining unsorted array + for (int j = i + 1; j < size; j++) { + if (arr[j] < arr[min_index]) { + min_index = j; + } + } + // Swap the found minimum element with the current element + int temp = arr[i]; + arr[i] = arr[min_index]; + arr[min_index] = temp; + } +} +int main() +{ + int arr[10],i; + printf("Enter array elements"); + for(i=0;i<10;i++) + { + scanf("%d",&arr[i]); + } + int size = sizeof(arr) / sizeof(arr[0]); + printf("Unsorted array: "); + for (int i = 0; i < size; i++) { + printf("%d ", arr[i]); + } + selectionSort(arr, size); + printf("\nSorted array: "); + for (int i = 0; i < size; i++) { + printf("%d ", arr[i]); + } + return 0; +}