#include<stdio.h>
#include<stdlib.h>
#define NULL 0
typedef struct LNode
{
struct LNode *next;
int data;
}LNode,*lnode;
void createList(lnode &l,int n)
{
lnode p,q;
l=(lnode)malloc(sizeof(LNode));
scanf("%d",&l->data);
p=l;
for(int i=1;i<n;i++)
{
q=(lnode)malloc(sizeof(LNode));
scanf("%d",&q->data);
p->next=q;
p=q;
}
p->next=NULL;
}
void rePrintList(lnode l)
{
if(l!=NULL) //要加括号
{
rePrintList(l->next);
printf("%d ",l->data);
}
}
void main()
{
int n;
lnode l;
scanf("%d",&n);
createList(l,n);
rePrintList(l);
printf("\n");
}
递归逆序输出链表
最新推荐文章于 2023-10-03 16:22:57 发布