Skip to content

Instantly share code, notes, and snippets.

@PeterStayPool
Last active February 25, 2016 11:50
finding h-index
#include <iostream>
#include <stdlib.h>
using namespace std;
int find_hindex(int *input, int s, int e, int last)
{
if (s > e)
return last;
int m = s+(e-s)/2;
if (input[m] >= m)
{
last = input[m];
s = m+1;
} else {
e = m-1;
}
return find_hindex(input, s, e, last);
}
int compare(const void *a, const void*b)
{
return (*(int*)b -*(int*)a);
}
int main()
{
int input[5] = {5, 3, 10, 4, 8};
qsort(input, 5, sizeof(int), compare);
cout << find_hindex(input, 0, 4, -1) << endl;
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment