递归访问链表的结点

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

 

posted @ 2020-05-06 10:16  Jinxiaobo0509  阅读(152)  评论(0)    收藏  举报