forked from Harshita-Kanal/Data-Structures-and-algorithms
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathselectionSort.cpp
More file actions
45 lines (38 loc) · 772 Bytes
/
selectionSort.cpp
File metadata and controls
45 lines (38 loc) · 772 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
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<int>v;
v.push_back(55);
v.push_back(555);
v.push_back(557);
v.push_back(1);
v.push_back(5);
v.push_back(65);
v.push_back(996);
v.push_back(69);
v.push_back(2);
v.push_back(3);
v.push_back(133);
v.push_back(189);
vector<int>vv = v;
sort(vv.begin(),vv.end());
for(int i = 0 ; i < v.size()-1 ; i++){
int minIndex = i;
for(int j = i+1 ; j < v.size() ; j++){
if(v[j] < v[minIndex]){
minIndex = j;
}
}
int temp = v[minIndex];
v[minIndex] = v[i];
v[i] = temp;
}
for(int i = 0 ; i < v.size() ; i++){
cout << v[i] << " ";
}
cout << endl;
for(int i = 0 ; i < v.size() ; i++){
cout << vv[i] << " ";
}
return 0;
}