-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselection.cpp
More file actions
41 lines (41 loc) · 955 Bytes
/
selection.cpp
File metadata and controls
41 lines (41 loc) · 955 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
40
41
/* Did some changes more to the program in the form of comments for step counter. Incase you are not getting the output comment remove the comments including this :P*/
#include<iostream>
using namespace std;
int main()
{
int a[15];
int i,j,k,t,c=0,n;
cout<<"\nEnter the number of data element to be sorted: ";
cin>>n;
cout<<"Enter Elements: ";
for(i = 0; i < n; i++)
{
cin>>a[i];
}
for(i=0;i<n;i++)
{
j=i;
c+=2;
for(k=i+1;k<n;k++)
{
if(a[k]<=a[j])
{
j=k;
c+=1;
}
c++;
}
//c+=2; //for false condition
t=a[i];
a[i]=a[j];
a[j]=t;
c+=3;
}
c+=1; //for false condition
for(i=0;i<n;i++)
{
std::cout <<a[i] << '\t';
}
std::cout << "\nc=" <<c<<std::endl;
return 0;
}