#include <bits/stdc++.h>

using namespace std;

struct node
{
int data;
struct node *next;
};
struct node *crea(int n)
{
int i;
struct node *head, *p;
head = (struct node *)malloc(sizeof(struct node));
head -> next = NULL;
for(i = 0; i < n; i ++)
{
p = (struct node *)malloc(sizeof(struct node));
scanf("%d", &p -> data);
p -> next = head -> next;
head -> next = p;
}
return head;
};
struct node *spilt(struct node *head)
{
struct node *head1, *p, *q;
int a = 0, b = 0;
head1 = (struct node *)malloc(sizeof(struct node));
head1 -> next = NULL;
p = head -> next;
head -> next = NULL;
q = p -> next;
while(p)
{
if(p -> data % 2 == 0)
{
p -> next = head -> next;
head -> next = p;
a++;
}
else
{
p -> next = head1 -> next;
head1 -> next = p;
b ++;
}
p = q;
if(q)
q = q -> next;
}
printf("%d %d\n",a,b);
return head1;
};
int main()
{ int n;
struct node *head, *p, *q, *head1;
scanf("%d", &n);
head = crea(n);
head1 = spilt(head);
p = head -> next;
while(p!=NULL)
{
if(p -> next != NULL)printf("%d ", p -> data);
else printf("%d\n", p ->data);
p = p -> next;
}
q = head1 -> next;
while(q!=NULL)
{
if(q -> next != NULL)printf("%d ", q -> data);
else printf("%d\n",q -> data);
q = q -> next;
}
return 0;
}

数据结构实验之链表五:单链表的拆分(SDUT 2120)的更多相关文章

  1. 数据结构实验之二叉树五:层序遍历 (SDUT 3344)

    #include <bits/stdc++.h> using namespace std; struct node { char data; struct node *lc, *rc; } ...

  2. 【Java】 大话数据结构(2) 线性表之单链表

    本文根据<大话数据结构>一书,实现了Java版的单链表. 每个结点中只包含一个指针域的链表,称为单链表. 单链表的结构如图所示: 单链表与顺序存储结构的对比: 实现程序: package ...

  3. 数据结构5: 链表(单链表)的基本操作及C语言实现

    逻辑结构上一个挨一个的数据,在实际存储时,并没有像顺序表那样也相互紧挨着.恰恰相反,数据随机分布在内存中的各个位置,这种存储结构称为线性表的链式存储. 由于分散存储,为了能够体现出数据元素之间的逻辑关 ...

  4. SDUT-3402_数据结构实验之排序五:归并求逆序数

    数据结构实验之排序五:归并求逆序数 Time Limit: 50 ms Memory Limit: 65536 KiB Problem Description 对于数列a1,a2,a3-中的任意两个数 ...

  5. SDUT OJ 数据结构实验之图论五:从起始点到目标点的最短步数(BFS)

    数据结构实验之图论五:从起始点到目标点的最短步数(BFS) Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss P ...

  6. SDUT 3344 数据结构实验之二叉树五:层序遍历

    数据结构实验之二叉树五:层序遍历 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Description 已知一个按 ...

  7. [C++]线性链表之单链表

    [文档整理系列] 线性链表之单链表 /* 问题描述:线性表____链表_____单链表 @date 2017-3-7 */ #include<iostream> using namespa ...

  8. SDUT OJ 数据结构实验之二叉树五:层序遍历

    数据结构实验之二叉树五:层序遍历 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descri ...

  9. SDUT 3402 数据结构实验之排序五:归并求逆序数

    数据结构实验之排序五:归并求逆序数 Time Limit: 40MS Memory Limit: 65536KB Submit Statistic Problem Description 对于数列a1 ...

  10. SDUT 3377 数据结构实验之查找五:平方之哈希表

    数据结构实验之查找五:平方之哈希表 Time Limit: 400MS Memory Limit: 65536KB Submit Statistic Problem Description 给定的一组 ...

随机推荐

  1. python 自动化测试

    安装selenium 安装命令: pip install selenium 测试 打开一款Python编辑器,默认Python自带的IDLE也行.创建 baidu.py文件,输入以下内容: from ...

  2. 用shell脚本安装MySQL-5.7.22-官方版本多实例

    Install_CentOS7_MySQL57_multi_instance.sh #!/bin/bash #请提前准备好参数文件my.cnf PORT=3307 InitMySQL() { mkdi ...

  3. 服务返回的json数据过大,nginx无法返回给client

    现象:请求同样的服务器,N多个接口中,只有一个接口未返回:从日志看,请求已到后端服务,并返回 解决方案:配置nginx缓冲大小 ###Nginx的缓冲区的大小 proxy_buffer_size 5m ...

  4. request.getScheme() 使用方法(转)

    今天在看代码时,发现程序使用了 request.getScheme() .不明白是什么意思,查了一下.结果整理如下: 1.request.getScheme() 返回当前链接使用的协议:一般应用返回h ...

  5. Docker 杂记

    1.配置阿里云加速 :可以找到各种加速URL.比如 https://tnxkcso1.mirror.aliyuncs.com/ 2.windows 配置: 3.docker info可以看到新的配置已 ...

  6. SCRUM 是一个用于开发和维护复杂产品的框架

    转自:http://www.scrumcn.com/agile/scrum-knowledge-library/scrum.html#tab-id-1 Scrum 是一个用于开发和维护复杂产品的框架 ...

  7. Java安全停止线程方法

    1. 早期Java提供java.lang.Thread类型包含了一些列的方法 start(), stop(), stop(Throwable) and suspend(), destroy() and ...

  8. 五:MVC使用数据库优先(DatabaseFirst)的方式创建数据模型

    1. ORM概念 2. EF的DatabaseFirst模式使用 1. ORM简介 对象关系映射(Object Relational Mapping,简称ORM) ORM技术特点: 1.提高了开发效率 ...

  9. asp.net 设计音乐网站

    第一步 收集资料 http://www.logoko.com.cn/    --设计logo网站 设计音乐文档  https://wenku.baidu.com/view/3d957617f18583 ...

  10. IDEA 运行报错:WARN: Establishing SSL connection

    使用JDBC连接数据库时出现报错, 报错内容:Wed Sep 26 14:30:31 CST 2018 WARN: Establishing SSL connection without server ...