您的位置:首页 > 其它

链表逆序输出

2014-06-20 21:53 253 查看
#include <iostream>
#include <cstdio>
#include <stdlib.h>
using namespace std;
struct ListNode
{
int m_value;
ListNode *m_pNext;
};
void PrintList(ListNode *pHead);
int main()
{
ListNode *pHead;
ListNode *pNode;
ListNode *pN;
pHead=(ListNode*)malloc(sizeof(ListNode));
pHead->m_pNext=NULL;
pNode=pHead;
int n;
int count=6;
while(count--)
{
pN=(ListNode*)malloc(sizeof(ListNode));
pNode->m_pNext=pN;
pNode=pN;
scanf("%d",&n);
pNode->m_value=n;
}
pNode->m_pNext=NULL;
PrintList(pHead->m_pNext);
return 0;
}
void PrintList(ListNode *pHead)
{
if(pHead!=NULL)
{
if(pHead->m_pNext!=NULL)
PrintList(pHead->m_pNext);
printf("%d\n",pHead->m_value);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  链表