#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);
}
}
转载于:https://www.cnblogs.com/xiaofeiwang/p/3825010.html
本文详细介绍了一种使用C++实现链表的方法,包括链表的创建和逆序遍历过程。通过具体代码示例,展示了如何动态分配内存创建链表节点,并采用递归方式打印链表元素。
461

被折叠的 条评论
为什么被折叠?



