在c中显示递归结构

时间:2015-08-22 21:52:01

标签: c recursion struct

    idx x, z ;
    for (x = 0 ; x < k ; ++x) { 
        if (mots[x].mot) { 
            printf("%s :", mots[x].mot) ;
            //Below not working properly how to write all my refs ?
            // printf("%i ", mots[x].refs -> cdr ->ref);
            // while (mots[x].refs -> cdr) printf("%i ", mots[x].refs -> ref); 
            printf("\n") ; 

如何在我的结构上正确迭代以显示mots [x]的每个引用?

我希望问题很清楚,提前谢谢

1 个答案:

答案 0 :(得分:1)

if (mots[x].mot) { 
    printf("%s :", mots[x].mot) ;
    struct node *node = mots[x].refs;
    while (node) {
         printf("%i ", node->ref);
         node = node->cdr;
    }
    printf("\n");
}