forked from MukulCode/CodingClubIndia
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelection sort.cpp
More file actions
75 lines (57 loc) · 853 Bytes
/
Selection sort.cpp
File metadata and controls
75 lines (57 loc) · 853 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include<iostream>
#define size 4
using namespace std;
class select
{
public:
int arr[size];
void get_data();
void display();
void selection_sort();
};
void select::get_data()
{
for(int i=0;i<size;i++)
{
cout<<"Enter data : ";
cin>>arr[i];
}
}
void select::display()
{
cout<<"\nSorted data \n\n";
for(int i=0;i<size;i++)
{
cout<<arr[i]<<"\t";
}
}
void select::selection_sort()
{
int temp;
int min;
for(int i=0;i<size-1;i++)
{
min = i;
for(int j=i+1;i<size;i++)
{
if(arr[j]<arr[min])
{
min = j;
}
if(min!=i)
{
temp = arr[i];
arr[i] = arr[min];
arr[min] = temp;
}
}
}
}
int main()
{
select s;
s.get_data();
s.selection_sort();
s.display();
return 0;
}