forked from CodeToExpress/dailycodebase
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathselectionSort.cpp
More file actions
44 lines (35 loc) · 796 Bytes
/
selectionSort.cpp
File metadata and controls
44 lines (35 loc) · 796 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
/*
* @author : imkaka
* @date : 2/1/2019
*
*/
#include<iostream>
using namespace std;
void selectionSort(int arr[], int size){
for(int i = 0; i < size; ++i){
for(int j = i+1; j < size; ++j){
if(arr[i] > arr[j]){
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
}
void print(int arr[], int size){
for(int x = 0; x < size; ++x){
cout << arr[x] << " ";
}
cout << endl;
}
int main(){
int arr[] = {20, 46, 2, 43, 10, -29, 10, 0, 12};
int size = sizeof(arr)/sizeof(arr[0]);
cout << "Before Sorting " << endl;
print(arr, size);
selectionSort(arr, size);
cout << endl;
cout << "After Sorting " << endl;
print(arr, size);
return 0;
}