FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
algorithm-examples/cpp-algorithm/src/sort/h_index.cpp at main · codejsha/algorithm-examples · GitHub
codejsha
/
algorithm-examples
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
2
Code
Issues
0
Pull requests
0
Discussions
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
algorithm-examples
/
cpp-algorithm
/
src
/
sort
/
h_index.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
44 lines (38 loc) · 1.06 KB
Breadcrumbs
algorithm-examples
/
cpp-algorithm
/
src
/
sort
/
h_index.cpp
Copy path
File metadata and controls
44 lines (38 loc) · 1.06 KB
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
43
44
#
include
"
h_index.h
"
#
include
<
algorithm
>
#
include
<
ranges
>
auto
HIndex::HIndex1
(std::vector<
int
>& citations) -> int
{
//
sort citations in descending order
std::ranges::sort
(citations, std::greater<>{});
//
std::sort(citations.begin(), citations.end(), std::greater<>());
int
h_index =
0
;
for
(
int
i =
0
; i <
static_cast
<
int
>(citations.
size
()); ++i)
{
//
if current citation is greater than or equal to the number of papers
if
(citations[i] >= i +
1
)
{
h_index = i +
1
;
}
else
{
break
;
}
}
return
h_index;
}
auto
HIndex::HIndex2
(std::vector<
int
>& citations) -> int
{
//
sort citations in descending order
std::ranges::sort
(citations, std::greater<>{});
//
std::sort(citations.begin(), citations.end(), std::greater<>());
for
(
int
i =
0
; i <
static_cast
<
int
>(citations.
size
()); ++i)
{
//
if current citation is less than the number of papers
if
(citations[i] < i +
1
)
{
return
i;
}
}
return
0
;
}
Back
|
FazBrowse Home
|
New Git URL