Skip to content

Commit ff87463

Browse files
Create 19selection_sort.cpp
1 parent 5ca0b29 commit ff87463

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

19selection_sort.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Online C++ compiler to run C++ program online
2+
#include<bits/stdc++.h>
3+
using namespace std;
4+
int main(){
5+
int n=5;
6+
int loc;
7+
int arr[5]={7,4,9,8,1};
8+
for(int i=0;i<(n-1);i++){
9+
int min=arr[i];
10+
loc=i;
11+
for(int j=i+1;j<n;j++){
12+
if(min>arr[j]){
13+
min=arr[j];
14+
loc=j;
15+
16+
}
17+
}
18+
int temp=arr[loc];
19+
arr[loc]=arr[i];
20+
arr[i]=temp;
21+
}
22+
23+
for(int i=0;i<n;i++){
24+
cout<<arr[i]<<" ";
25+
}
26+
27+
return 0;
28+
}

0 commit comments

Comments
 (0)