FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
competitive-programming/Sorting/Selection Sort.cpp at master · kothariji/competitive-programming · GitHub
kothariji
/
competitive-programming
Public
Notifications
You must be signed in to change notification settings
Fork
500
Star
704
Code
Issues
1
Pull requests
2
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
competitive-programming
/
Sorting
/
Selection Sort.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
42 lines (35 loc) · 775 Bytes
Breadcrumbs
competitive-programming
/
Sorting
/
Selection Sort.cpp
Copy path
File metadata and controls
42 lines (35 loc) · 775 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#
include
<
iostream
>
using
namespace
std
;
void
selectionSort
(
int
arr[]) {
for
(
int
i =
0
; i <
4
; i++) {
int
min = i;
for
(
int
j = i +
1
; j <
5
; j++) {
if
(arr[j] < arr[min]) {
min = j;
}
}
if
(min != i) {
int
temp = arr[min];
arr[min] = arr[i];
arr[i] = temp;
}
}
}
int
main
() {
int
myarr[
5
];
cout <<
"
Enter 5 integers in random order:
"
<< endl;
for
(
int
i =
0
; i <
5
; i++) {
cin >> myarr[i];
}
cout <<
"
UNSORTED ARRAY:
"
<< endl;
for
(
int
i =
0
; i <
5
; i++) {
cout << myarr[i] <<
"
"
;
}
cout << endl;
selectionSort
(myarr);
//
sorting actually happening
cout <<
"
SORTED ARRAY:
"
<< endl;
for
(
int
i =
0
; i <
5
; i++) {
cout << myarr[i] <<
"
"
;
}
return
0
;
}
Back
|
FazBrowse Home
|
New Git URL