#include <stdio.h>
#include <stdlib.h>
typedef struct LNode{
int data;
struct LNode *next;
}*LinkList, LNode;
//创建链表
void create(LinkList L, int num)
{
// L=(LinkList)malloc(sizeof(LNode));
int i;
LNode *p;
p=L;
for(i=0; i<num; i++) {
LNode *temp;
temp=(LinkList)malloc(sizeof(LNode));
scanf("%d",&temp->data);
temp->next=NULL;
p->next=temp;
p=temp;
}
}
//打印链表各元素
void show(LinkList L)
{
LNode *p;
p=L->next;
while(p!=NULL) {
printf("%d ", p->data);
p=p->next;
}
printf("\n");
}
//逆序
void inverse(LinkList L, LinkList LL)
{
LNode *q, *t;
LL->next=NULL;
q=L->next;
while(q)
{
t=(LinkList)malloc(sizeof(LNode));
t->data=q->data;
t->next=LL->next;
LL->next=t;
q=q->next;
}
}
void main()
{
int num;
LinkList L, LL;
L=(LinkList)malloc(sizeof(LNode));
LL=(LinkList)malloc(sizeof(LNode));
printf("链表元素数为:");
scanf("%d", &num);
create(L, num);
show(L);
inverse(L, LL);
show(LL);
}
没有合适的资源?快使用搜索试试~ 我知道了~
linklist-reverse.rar_linklist reverse
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
15 浏览量
2022-09-24
12:49:49
上传
评论
收藏 6KB RAR 举报
本程序的功能:创建链表、并逆序显示链表中的各个元素
资源详情
资源评论
资源推荐
收起资源包目录









共 7 条
- 1
- 2













Kinonoyomeo
- 粉丝: 17
- 资源: 1万+

上传资源 快速赚钱
我的内容管理 收起
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助

会员权益专享
安全验证
文档复制为VIP权益,开通VIP直接复制

评论0