Initialize the linked list node

In the previous article, we introduced the establishment, traversal, insertion and deletion of linked lists. One problem is that when inserting, the second parameter is a ListNode* node, so how do we initialize a separate linked list when calling For nodes, the answer is to define an initialization function

struct ListNode
{
    int num;
    ListNode* next;
    ListNode(int n = 0, ListNode *p = NULL)   
    { num = n; next = p;}  
};

Default parameters are 0 and NULL

If you see other methods, I will continue to add them, and welcome to leave a message

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325209492&siteId=291194637