簡體   English   中英

我的老師做了這個功能,但我不明白它有什么用

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM