数据结构-单链表反转
来源:互联网 发布:2008年科比总决赛数据 编辑:程序博客网 时间:2024/06/06 04:00
#include<stdio.h>
#include<malloc.h>
typedef struct Node
{
int data;
struct Node *next;
}List;
List *Creat()
{
int i,m;
scanf("%d",&m);
List *head;
List *p1,*p2;
p1=p2=(List *)malloc(sizeof(List));
head=p1;
for(i=0;i<m;i++)
{
scanf("%d",&p1->data);
p2=p1;
p1=(List *)malloc(sizeof(List));
p2->next=p1;
}
p2->next=NULL;
return head;
}
List *Reverse(List *head1)
{
List *p1,*p2,*p3;
List *head;
head=NULL;
p1=head1;
p2=p1->next;
while(p2)
{
p3=p2->next;
p2->next=p1;
p1=p2;
p2=p3;
}
head1->next=NULL;
head=p1;
return head;
}
void print(List *head1)
{
List *p;
p=head1;
while(p)
{
printf("%d ",p->data);
p=p->next;
}
printf("\n");
}
int main()
{
List *head1;
List *head2;
head1=Creat();
head2=Reverse(head1);
print(head2);
}
#include<malloc.h>
typedef struct Node
{
int data;
struct Node *next;
}List;
List *Creat()
{
int i,m;
scanf("%d",&m);
List *head;
List *p1,*p2;
p1=p2=(List *)malloc(sizeof(List));
head=p1;
for(i=0;i<m;i++)
{
scanf("%d",&p1->data);
p2=p1;
p1=(List *)malloc(sizeof(List));
p2->next=p1;
}
p2->next=NULL;
return head;
}
List *Reverse(List *head1)
{
List *p1,*p2,*p3;
List *head;
head=NULL;
p1=head1;
p2=p1->next;
while(p2)
{
p3=p2->next;
p2->next=p1;
p1=p2;
p2=p3;
}
head1->next=NULL;
head=p1;
return head;
}
void print(List *head1)
{
List *p;
p=head1;
while(p)
{
printf("%d ",p->data);
p=p->next;
}
printf("\n");
}
int main()
{
List *head1;
List *head2;
head1=Creat();
head2=Reverse(head1);
print(head2);
}
1 0
- 数据结构之单链表反转
- [数据结构]单链表反转
- 《数据结构》单链表反转
- 数据结构之单链表反转
- 数据结构-单链表反转
- 数据结构 - 反转单链表(C++)
- 数据结构——反转单链表
- 数据结构之Java单链表反转
- 算法学习之数据结构之单链表反转,两两反转
- 数据结构_单链表的建立与反转
- 单链表的反转(数据结构 面试题)
- 数据结构1:单链表反转(转载)
- 【数据结构】看图理解单链表的反转
- 5.数据结构单链表之链表反转
- 反转链表[数据结构]
- 反转链表[数据结构]
- 链表反转-数据结构
- 数据结构与算法之链表(三)单链表反转
- TypeScript
- Git的使用一:下载安装
- PAT 乙等 1009 C语言
- 数字逻辑练习题
- Fragment的使用(切换)
- 数据结构-单链表反转
- JVM初窥:javac命令
- nodejs+sequelize同步模型到mysql数据库
- lib + namespace
- 装饰者设置模式和代理模式的区别
- jbpm(java 业务流程管理)
- 多线程的那点儿事(之死锁)
- 51nod 1433 0和5(数学)
- 一文读懂SCAN