嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元微信扫码支付:2 元
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
C语言链表创建与逆序输出
#include <stdio.h>
#include <stdlib.h>
#define N sizeof(struct x)
struct x
{
int num;
struct x *next;
};
struct x *creat(void)
{
struct x *p1,*p2,*head;
head=p2=(struct x *)malloc(N); //head,p2指向头结点
p1=(struct x *)malloc(N); //p1创建新结点
scanf("%d",&p1->num);
while(p1->num!=-1)
{
p2->next=p1; //连接p2->p1两个结点
p2=p1; //p2向p1挪动
p1=(struct x *)malloc(N); //p1创建新结点
scanf("%d",&p1->num);
}
p2->next=NULL;
free(p1); //删除结束结点
return head;
}
void print(struct x *p)
{
p=p->next;
if (p->next==NULL)
{
printf("%d ",p->num);
}
else
{
print(p);
printf("%d ",p->num);
}
}
int main()
{
struct x *head;
head=creat();
print(head);
return 0;
}