【发布时间】:2011-09-12 23:48:51
【问题描述】:
我需要从存储在树中的出版物列表中计算h-index。
我所做的是按递减顺序遍历树,获取引用位置数列表
看起来像:
line 1 10
line 2 5
line 3 4
line 4 0
我应该在第 3 行停止并返回 3。问题在于给出的示例,在这种情况下
line 1 4
line 2 0
line 3 0
它在 2 处停止,因为 4>1 但 0>3 为假。它应该返回 1。你能解释一下为什么吗?我知道这更像是一道数学题,但在那之后,如果出现严重错误,我可能需要重新实现它。
这里是代码
int index_h_calc(rbtree_node n, int *i){
if (n == NULL) {
fputs("<empty tree>\n", stdout);
return 0;
}
if (n->right != NULL)
index_h_calc(n->right,i);
graduat *grad;
grad=n->value;
if(DEBUG)
printf("linea %d %d %s\n ",*i,(int)grad->tot,grad->name);
if(*i+1>=(int)grad->tot) {
return *i;
} else
*i+=1;
if (n->left != NULL)
index_h_calc(n->left,i);
return *i;
}
【问题讨论】:
标签: c algorithm list tree sorted