Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8c5b7ca

Browse files
add comments
1 parent 59d02cf commit 8c5b7ca

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

nth_element.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
#include <vector>
22
#include <iostream>
3+
#include <algorithm> //nth_element
34

45
//https://en.cppreference.com/w/cpp/algorithm/nth_element
56

7+
/*
8+
It only put the nth largest/smallest element in the right position
9+
, other elements may not in sorted position!
10+
*/
611
int main(){
712
std::vector<int> myvec = {1,3,6,2,9,5};
813
int n = 3;
@@ -15,4 +20,4 @@ int main(){
1520
return 0;
1621
}
1722

18-
//The 3 largest values are : 9 6 5
23+
//The 3 largest values are : 6 9 5

0 commit comments

Comments
 (0)