剑指Offer之从尾到头打印链表(题5)






1 /****************************************                                                                                                 
  2     > File Name:stack_test.cpp
  3     > Author:xiaoxiaohui
  4     > mail:1924224891@qq.com
  5     > Created Time:2016年05月19日 星期四 21时01分44秒
  6 ****************************************/
  7 
  8 #include<iostream>
  9 using namespace std
 10 
 11 void print(ListNode* phead)
 12 {
 13     stack<ListNode*> node;
 14 
 15     ListNode* tem = phead;
 16     while(tem != NULL)
 17     {
 18         node.push(tem);
 19         tem = tem->m_pNext;
 20     }
 21 
 22     while(!node.empty())
 23     {
 24         tem = node.top();
 25         printf("%d  ", tem->m_nValue);
 26         node.pop();
 27     }
 28 }





1 /****************************************                                                                                                 
  2     > File Name:digui_test.c
  3     > Author:xiaoxiaohui
  4     > mail:1924224891@qq.com
  5     > Created Time:2016年05月19日 星期四 20时48分02秒
  6 ****************************************/
  7 
  8 #include<stdio.h>
  9 
 10 void print(ListNode* phead)
 11 {
 12     ListNode* tem = phead;
 13     if(tem == NULL)
 14     {
 15         return;
 16     }
 17     else
 18     {
 19         print(tem->m_pNext);
 20         printf("%d  ",tem->m_nKey);
 21     }
 22 }