Single linked list

前端 未结 7 706
無奈伤痛
無奈伤痛 2021-01-23 13:54

I have created a single linked list. Everything works fine.

I just want to know if I have done anything potentially dangerous in my code. The code snippets I am concern

7条回答
  •  盖世英雄少女心
    2021-01-23 13:54

    Is there any reason you call exit(0) from clean_up function? I think this is potential dangerous, since you don't give a chance to the user to finish program correctly.

    As well I would suggest you to use data encapsulation when you building up you data structure:

    typedef struct
    {
        int product_code;
        char product_name[128];
        int product_cost;
        list_node *next;
    } list_node;
    
    typedef struct
    {
       list_node* head;
       list_node* tail;
       list_node* current;
       int        size;
    } list;
    

    Also it's a good practice to use trail dummy node at the head of your list to make your code more generic.

提交回复
热议问题