Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions Selection
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <stdio.h>
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;
}