File tree 2 files changed +82
-0
lines changed
University Algo Course/Sorting/Selection Sort 2 files changed +82
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < bits/stdc++.h>
2
+ using namespace std ;
3
+
4
+ #define flush cin.ignore(numeric_limits<streamsize>::max(),' \n ' )
5
+ #define FASTERIO ios_base::sync_with_stdio (0 ); cin.tie(0 ); cout.tie(0 )
6
+
7
+
8
+ void selection_sort (vector<int >arr) {
9
+
10
+ int sm = 0 ;
11
+ for (int i = 0 ; i < arr.size (); i++) {
12
+ sm = i;
13
+ for (int j = i + 1 ; j < arr.size (); j++) {
14
+ if (arr[sm] > arr[j])sm = j;
15
+ }
16
+ swap (arr[i], arr[sm]);
17
+ }
18
+ for (auto it : arr)cout << it << " " ;
19
+ }
20
+
21
+ int main () {
22
+
23
+ #ifdef anikakash
24
+ clock_t tStart = clock ();
25
+ freopen (" input.txt" , " r" , stdin);
26
+ freopen (" out.txt" , " w" , stdout);
27
+ #endif
28
+
29
+ int n; cin >> n;
30
+ vector<int >arr (n);
31
+ int sm = INT_MAX;
32
+ for (int i = 0 ; i < n; i++) {
33
+ cin >> arr[i];
34
+ }
35
+ selection_sort (arr);
36
+
37
+ #ifdef anikakash
38
+ fprintf (stderr, " \n >> Runtime: %.10fs\n " , (double ) (clock () - tStart) / CLOCKS_PER_SEC);
39
+ #endif
40
+ return 0 ;
41
+ }
Original file line number Diff line number Diff line change
1
+ #include < bits/stdc++.h>
2
+ using namespace std ;
3
+
4
+ #define flush cin.ignore(numeric_limits<streamsize>::max(),' \n ' )
5
+ #define FASTERIO ios_base::sync_with_stdio (0 ); cin.tie(0 ); cout.tie(0 )
6
+
7
+
8
+ void selection_sort (vector<char >arr) {
9
+
10
+ int sm = 0 ;
11
+ for (int i = 0 ; i < arr.size (); i++) {
12
+ sm = i;
13
+ for (int j = i + 1 ; j < arr.size (); j++) {
14
+ if (arr[sm] > arr[j])sm = j;
15
+ }
16
+ swap (arr[i], arr[sm]);
17
+ }
18
+ for (auto it : arr)cout << it << " " ;
19
+ }
20
+
21
+ int main () {
22
+
23
+ #ifdef anikakash
24
+ clock_t tStart = clock ();
25
+ freopen (" input.txt" , " r" , stdin);
26
+ freopen (" out.txt" , " w" , stdout);
27
+ #endif
28
+
29
+ int n; cin >> n;
30
+ vector<char >arr (n);
31
+ int sm = INT_MAX;
32
+ for (int i = 0 ; i < n; i++) {
33
+ cin >> arr[i];
34
+ }
35
+ selection_sort (arr);
36
+
37
+ #ifdef anikakash
38
+ fprintf (stderr, " \n >> Runtime: %.10fs\n " , (double ) (clock () - tStart) / CLOCKS_PER_SEC);
39
+ #endif
40
+ return 0 ;
41
+ }
You can’t perform that action at this time.
0 commit comments