How to display a linked list in a structure in C

typedef struct child_list {int count; char vo[100]; child_list*next;} child_list;
typedef struct parent_list
{ char vo[100];
child_list * head;
int count;
parent_list * next; } parent_list;

      

As you can see, there are two structures. child_list

used to create a linked list. And this list will be saved in the linked list of the parent list. My problem is displaying the child list that is in parent_list

.

My desire to get when displaying a linked list parent_list

:

The work with this logic is listed here. I have already done append and other things.

For example, if I enter ab cd ab ja cd ab

Word    Count    List

ab        3      cd->ja

cd        2      ab->ab

ja        1      cd

      

The problematic part is displaying child_list

which is in the nodes parent_list

(output list column). I don't know my question is clear, please ask for more information.

+2


a source to share


1 answer


If you just want to print the parent node with its child list, you can do the following:



void print_node(parent_list *parent_node) {
    printf("%s\t%d\t", parent_node->vo, parent_node->count);

    child_list *child_node = parent_node->head;
    while (child_node != NULL) {
        printf("%s", child_node->vo);

        child_node = child_node->next;

        if (child_node != NULL) {
            printf("->");
        }
    }
    printf("\n");
}

      

+1


a source







All Articles