递归访问链表的结点
1 void traverse(ListNode* head) 2 { 3 if(!head) return; 4 //cout << head->val << " "; // 正序访问链表 5 traverse(head->next); 6 //cout << head->val << " "; // 逆序访问链表 7 }
Mamba never out
1 void traverse(ListNode* head) 2 { 3 if(!head) return; 4 //cout << head->val << " "; // 正序访问链表 5 traverse(head->next); 6 //cout << head->val << " "; // 逆序访问链表 7 }