单链表的拆分
来源:互联网 发布:数据恢复精灵破解版 编辑:程序博客网 时间:2024/05/18 17:24
#include<stdio.h>
#include<malloc.h>
struct node
{
int data;
struct node *next;
};
struct node *creat(int n)
{
struct node *head,*p,*tail;
head=(struct node *)malloc(sizeof(struct node));
head->next=NULL;
tail=head;
int i;
for(i=0;i<n;i++)
{
p=(struct node *)malloc(sizeof(struct node));
scanf("%d",&p->data);
p->next=NULL;
tail->next=p;
tail=p;
}
return head;
}
void print(struct node *head,int n)
{
struct node *p;
p=head->next;
int t=n-1;
while(t--)
{
printf("%d ",p->data);
p=p->next;
}
printf("%d\n",p->data);
}
void chai(struct node *head)
{
struct node *head1,*head2,*p,*p1,*p2;
int c=0,d=0;
head1=(struct node *)malloc(sizeof(struct node));
head1->next=NULL;
p1=head1;
head2=(struct node *)malloc(sizeof(struct node));
head2->next=NULL;
p2=head2;
p=head->next;
while(p)
{
if(p->data%2==0)
{
c++;
p1->next=p;
p1=p;
}
else
{
d++;
p2->next=p;
p2=p;
}
p=p->next;
}
printf("%d %d\n",c,d);
print(head1,c);
print(head2,d);
}
int main()
{
int n;
struct node *head;
scanf("%d",&n);
head=creat(n);
chai(head);
return 0;
}
#include<malloc.h>
struct node
{
int data;
struct node *next;
};
struct node *creat(int n)
{
struct node *head,*p,*tail;
head=(struct node *)malloc(sizeof(struct node));
head->next=NULL;
tail=head;
int i;
for(i=0;i<n;i++)
{
p=(struct node *)malloc(sizeof(struct node));
scanf("%d",&p->data);
p->next=NULL;
tail->next=p;
tail=p;
}
return head;
}
void print(struct node *head,int n)
{
struct node *p;
p=head->next;
int t=n-1;
while(t--)
{
printf("%d ",p->data);
p=p->next;
}
printf("%d\n",p->data);
}
void chai(struct node *head)
{
struct node *head1,*head2,*p,*p1,*p2;
int c=0,d=0;
head1=(struct node *)malloc(sizeof(struct node));
head1->next=NULL;
p1=head1;
head2=(struct node *)malloc(sizeof(struct node));
head2->next=NULL;
p2=head2;
p=head->next;
while(p)
{
if(p->data%2==0)
{
c++;
p1->next=p;
p1=p;
}
else
{
d++;
p2->next=p;
p2=p;
}
p=p->next;
}
printf("%d %d\n",c,d);
print(head1,c);
print(head2,d);
}
int main()
{
int n;
struct node *head;
scanf("%d",&n);
head=creat(n);
chai(head);
return 0;
}
0 0
- 单链表的拆分
- 单链表的拆分
- 单链表的拆分
- 单链表的拆分
- 单链表的拆分
- 单链表的拆分
- 单链表的拆分 SDUT -2120
- 单链表的链表拆分
- 链表F 单链表的拆分
- 拆分单链表
- 单链表拆分
- 数据结构实验之链表五:单链表的拆分
- 数据结构实验之链表五:单链表的拆分
- 数据结构实验之链表五:单链表的拆分
- 数据结构实验之链表五:单链表的拆分
- 数据结构实验之链表五:单链表的拆分
- 数据结构实验之链表五:单链表的拆分
- 数据结构实验之链表五:单链表的拆分
- 100亿个数字排序
- RxJava结合Retrofit如何避免覆盖http请求(终端当前http请求)
- 真机安装搜狗输入法Assertion failure in -[UICGColor encodeWithCoder:]
- 第38个python程序:列表的操作
- 第五周项目4 —— 数制转换
- 单链表的拆分
- Eclipse如何解决启动慢?
- Linklist模仿队
- 3线 spi 总线设计
- 2016-10-08
- netty入门学习
- Odoo ORM API(五)- Fields
- 微信双11活动预热草稿
- 第七周项目4-队列数组