| | |
| | | INIT_LIST_HEAD(&head); |
| | | |
| | | /* Create the link list */ |
| | | printf("Create link list:\n"); |
| | | for(i=0; i<10; i++) |
| | | { |
| | | node = malloc(sizeof(*node)); |
| | |
| | | printf("List add an node data : %p->%d\n", node, node->data); |
| | | list_add_tail(&node->list, &head); |
| | | } |
| | | printf("\n"); |
| | | |
| | | /* Use list_for_each_entry to travel list, we can not remove the node in it */ |
| | | printf("\nTraversing the list:\n"); |
| | | list_for_each_entry(node, &head, list) |
| | | { |
| | | printf("List travel node data : %p->%d\n", node, node->data); |
| | | } |
| | | printf("\n"); |
| | | |
| | | /* Use list_for_each_entry_safe to destroy the list */ |
| | | printf("\nDestroy link list:\r\n"); |
| | | list_for_each_entry_safe(node, tmp, &head, list) |
| | | { |
| | | printf("List remove node data : %p->%d\n", node, node->data); |
| | | list_del(&node->list); |
| | | free(node); |
| | | free(node); |
| | | } |
| | | printf("\n"); |
| | | |