-
Notifications
You must be signed in to change notification settings - Fork 0
/
selection_sort.cpp
27 lines (26 loc) · 986 Bytes
/
selection_sort.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include<iostream>
using namespace std;
int main()
{
int arr[100],i,j,arr_length;
cin>>arr_length; //input array length less than 100
for(i=0;i<arr_length;i++) cin>>arr[i];
for(i=0;i<arr_length;i++)
{
int index=i,min;
min=arr[i];
for(j=i;j<arr_length;j++)
{
if(arr[j]<min)
{
min=arr[j];
index=j;
}
}
arr[index]=arr[i];
arr[i]=min;
}
for(i=0;i<arr_length;i++) cout<<arr[i]<<" ";
cout<<endl;
system("pause");
}