5.从尾到头打印链表

来源:互联网 发布:apache超时时间设置 编辑:程序博客网 时间:2024/06/06 00:10
#include <iostream>#include <stack>using namespace std;struct ListNode{    int m_nValue;    ListNode* m_pNext;};void PrintReverseList(ListNode* pHead){    if(pHead == nullptr)        return;    stack<ListNode*> nodes;    ListNode* pNode = pHead;    while(pNode != nullptr)    {        nodes.push(pNode);    }    while(!nodes.empty())    {        cout<<nodes.top()->m_nValue<<"\t";        nodes.pop();    }}int main(){    cout << "Hello world!" << endl;    return 0;}
1 0
原创粉丝点击