File tree Expand file tree Collapse file tree 1 file changed +47
-0
lines changed
Expand file tree Collapse file tree 1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change 1+ /*
2+ Author: Shubhendra Singh
3+ Github: shubhendra-20
4+ */
5+
6+ #include < iostream>
7+ using namespace std ;
8+ void swap (int *xp, int *yp)
9+ {
10+ int temp = *xp;
11+ *xp = *yp;
12+ *yp = temp;
13+ }
14+ void selectionSort (int arr[], int n)
15+ {
16+ int i, j, min_idx;
17+
18+ for (i = 0 ; i < n-1 ; i++)
19+ {
20+ min_idx = i;
21+ for (j = i+1 ; j < n; j++)
22+ if (arr[j] < arr[min_idx])
23+ min_idx = j;
24+
25+ swap (&arr[min_idx], &arr[i]);
26+ }
27+ }
28+ void printArray (int arr[], int size)
29+ {
30+ int i;
31+ for (i=0 ; i < size; i++)
32+ cout<<arr[i]<<" " ;
33+ }
34+ int main ()
35+ {
36+ int n;
37+ cin>>n;
38+ int a[n];
39+ int i;
40+ for (i=0 ;i<n;i++)
41+ {
42+ cin>>a[i];
43+ }
44+ selectionSort (a, n);
45+ printArray (a, n);
46+ return 0 ;
47+ }
You can’t perform that action at this time.
0 commit comments