面试题六:从尾到头打印链表

方法1:定义栈结构,遍历链表将值存在栈里面,然后再出栈打印 O(n)
方法2:递归的本质也是栈,但是链表过长的话可能会造成内存溢出

    void  f1(ListNode * head){
                    if(head!=null)
                            if(head->next!=null)
                                f1(head->next);
                    cout>>head.date>>endl;        
            }

 

posted @ 2020-03-29 14:19  浪波激泥  阅读(239)  评论(0编辑  收藏  举报