forked from techyminati/python_codes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelection_Sort.cpp
More file actions
51 lines (51 loc) · 906 Bytes
/
Copy pathSelection_Sort.cpp
File metadata and controls
51 lines (51 loc) · 906 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
42
43
44
45
46
47
48
49
50
51
#include <iostream>
using namespace std;
int* rdm(int n)
{
int b;
int *arr=new int[n];
srand(time(0));
for(int i=0;i<n;i++)
{
b=1+(rand()%100);
arr[i]=b;
}
return arr;
}
int main()
{
int n,a;
cout<<"input the size of the array = ";
cin>>n;
int* ptr;
ptr=rdm(n);
cout<<"our randam array = "<<" ";
for(int i=0;i<n;i++)
cout<<ptr[i]<<" ";
for(int i=0;i<(n-1);i++)
{
int min=i;
for(int j=(i+1);j<n;j++)
{
if(ptr[min]>ptr[j])
min=j;
}
if(min!=i)
{
int temp=ptr[min];
ptr[min]=ptr[i];
ptr[i]=temp;
}
cout<<endl;
cout<<"array after "<<i+1<<" pass = ";
for(int k=0;k<n;k++)
{
cout<<ptr[k]<<" ";
}
cout<<endl;
}
cout<<"sorted array = "<<" ";
for(int i=0;i<n;i++)
cout<<ptr[i]<<" ";
return 0;
}