Asked by
AL MaMun (4 Golds)
Friday, 31 Jul 2020, 04:44 PM
at (Education
Tutorials)
|
|
|
|
#include<bits/stdc++.h> int action(int A[], int n) { int i, j, index_min, temp; for(i=0; i<n-1; i++) { index_min = i; for(j=i+1; j<n; j++) { if(A[j] < A[index_min]) { index_min = j; } } if(index_min != i) { temp = A[i]; A[i] = A[index_min]; A[index_min] = temp; } } } int main() { int a[10] = {11, 3, 52, 9, 112}; action(a, 5); for(int i=0; i<5; i++) printf("%d ", a[i]); return 0; } |
C Program of Selection sort data structure and algorithm : #include<stdio.h> int main() { int i, j, n, arr[100], min, temp; scanf("%d", &n); for(i=0; i<n; i++) scanf("%d", &arr[i]); for(i=0; i<n-1; i++) { min=i; for(j=i+1; j<n; j++) { if(arr[j]<arr[min]) min=j; } temp=arr[i]; arr[i]=arr[min]; arr[min]=temp; } for(i=0; i<n; i++) printf("%d ", arr[i]); return 0; } |