![](/img/trans.png)
[英]I don't understand what's buggy with my pset4[more comfortable(edges)] code
[英]My teacher made this function but i don't understand what's the use of it
我正在練習鏈表。 我們的老師向我們展示了構建新節點和列表的標准函數。
在以下函數中,我不明白輔助函數 infoGreater 的用途是什么。
這就是函數 infoGreater 的構建方式:
int infoGreater (TInfo info1, TInfo info2) {
return info1 > info2;
}
我的意思是 return 是什么。 我不明白。 它返回什么? 為什么它說 info1>info2 ? 那是什么
這是主要功能:
TList listInsert(TList list, TInfo info) {
TNode *node = nodeCreate(info);
assert (node != NULL);
TNode *prec = NULL, *succ = list;
while (succ != NULL && infoGreater(info, succ->info)) {
prec = succ;
succ = succ->link;
}
node->link = succ;
if (prec == NULL)
list = node;
else
prec->link = node;
return list;
}
主要的疑問是什么return info1>info2;
做? 它返回什么? 為什么在主函數 listInsert 中是必要的?
函數infoGreater
是微不足道的。 這有點令人困惑,因為缺少一些隱式類型轉換。 函數的返回類型是int
,它非常典型地用於存儲布爾值。
該函數返回一個布爾值。 如果info1
更大, info1
1(或理論上任何其他非零值), info1
為 0。
代碼相當於:
int infoGreater (TInfo info1, TInfo info2) {
if (info1 > info2)
return 1;
else
return 0;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.