数据结构实验之链表三:链表的逆置
来源:互联网 发布:mac相簿批量删除照片 编辑:程序博客网 时间:2024/04/30 01:54
#include <stdio.h>
#include <malloc.h>
struct node
{
int data;
struct node *next;
};
int main()
{
struct node *head,*p,*tail,*q,*r;
head=(struct node*)malloc(sizeof(struct node));
head->next=NULL;
tail=head;
while(1)
{
p=(struct node*)malloc(sizeof(struct node));
scanf("%d",&p->data);
if(p->data==-1)break;
p->next=NULL;
tail->next=p;
tail=p;
}
p=head->next;
head->next=NULL;
q=p->next;
while(p)
{
p->next=head->next;
head->next=p;
p=q;
if(q)
q=q->next;
}
r=head;
while(r->next!=NULL)
{
printf("%d ",r->next->data);
r=r->next;
}
return 0;
}
#include <malloc.h>
struct node
{
int data;
struct node *next;
};
int main()
{
struct node *head,*p,*tail,*q,*r;
head=(struct node*)malloc(sizeof(struct node));
head->next=NULL;
tail=head;
while(1)
{
p=(struct node*)malloc(sizeof(struct node));
scanf("%d",&p->data);
if(p->data==-1)break;
p->next=NULL;
tail->next=p;
tail=p;
}
p=head->next;
head->next=NULL;
q=p->next;
while(p)
{
p->next=head->next;
head->next=p;
p=q;
if(q)
q=q->next;
}
r=head;
while(r->next!=NULL)
{
printf("%d ",r->next->data);
r=r->next;
}
return 0;
}
0 0
- 数据结构实验之链表三:链表的逆置
- 数据结构实验之链表三:链表的逆置
- 数据结构实验之链表三:链表的逆置
- 数据结构实验之链表三:链表的逆置
- 数据结构实验之链表三:链表的逆置
- 数据结构实验之链表三:链表的逆置
- 数据结构实验之链表三:链表的逆置
- 数据结构实验之链表三:链表的逆置
- 【2118】数据结构实验之链表三:链表的逆置
- 数据结构实验之链表三:链表的逆置
- 数据结构实验之链表三:链表的逆置
- 数据结构实验之链表三:链表的逆置
- 数据结构实验之链表三:链表的逆置
- OJ 数据结构实验之链表三:链表的逆置
- 数据结构实验之链表三:链表的逆置
- 数据结构实验之链表三:链表的逆置
- 数据结构实验之链表三:链表的逆置
- 数据结构实验之链表三:链表的逆置
- C++的函数指针
- JDeveloper IDE 12C 版本 运行页面报500错误 没有值"netscape" 的枚举常量
- libevent使用ndk-r8d编译
- 寒假第二天--线性表--数据结构上机测试2-2:单链表操作B
- 软件性能调优系列--知识点1
- 数据结构实验之链表三:链表的逆置
- 7bit 编码
- 同时运行两个脚本
- 寒假第二天--线性表--多项式求和
- 关键字 const
- 编程之美--求数组的子数组之和的最大值
- HDU 1226(bfs,大数求余)
- 实现的小功能:判断报名是否重复,是返回true,否返回false.
- SAE 和 AWS 以及其它