-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathSelectionSort.cpp
More file actions
39 lines (39 loc) · 836 Bytes
/
SelectionSort.cpp
File metadata and controls
39 lines (39 loc) · 836 Bytes
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
28
29
30
31
32
33
34
35
36
37
38
39
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cout<<endl<<"Enter the Size of the array"<<endl;
cin>>n;
cout<<"======================================="<<endl;
cout<<"Enter the elements of the array"<<endl;
int arr[n];
for(int i=0;i<n;i++)
{
cin>>arr[i];
}
int min,temp,position;
for(int i=0;i<n-1;i++)
{
min=arr[i];
position=i;
for(int j=i+1;j<n;j++)
{
if(arr[j]<min)
{
min=arr[j];
position=j;
}
}
temp=arr[position];
arr[position]=arr[i];
arr[i]=temp;
}
cout<<"======================================="<<endl;
cout<<"Sorted Array is "<<endl;
for(int i=0;i<n;i++)
{
cout<<arr[i]<<" ";
}
return 0;
}