我需要從存儲在樹中的出版物列表中計算。計算h指數
我所做的是遍歷樹在變小訂單獲取引文
它看起來像的位置數的列表:
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;
}
......應該不是,「然後返回h-index爲* n * - 1」?否則,這聽起來對我來說... – Dmitri 2011-12-28 21:15:40
@Dmitri:不,它必須是'我 - 1'。考慮OT的第一個例子:我們在第4行停止(因爲'0'4')並且返回'4-1 = 3'的h索引。在第二個例子中,我們停在第2行並返回1。 – deprecated 2011-12-30 23:19:26
哎呀..當我寫道,因爲某種原因,我腦子裏有'n'和''後腦。 – Dmitri 2011-12-30 23:36:34