#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. mysqlbinlog实战

    关于mysqlbinlog命令,下列参数应用频率较高:--base64-output:选项有三个参数,never表示不处理ROW格式日志,只处理传统的基于STATEMENT格式日志.decode-ro ...

  2. Spring Boot 获取Bean对象实体

    一.实现 ApplicationContextAware 接口 package com.zxguan; import org.springframework.beans.BeansException; ...

  3. C#之Action和Func

    以前我都是通过定义一个delegate来写委托的,但是最近看一些外国人写的源码都是用action和func方式来写,当时感觉对这很陌生所以看起源码也觉得陌生,所以我就花费时间来学习下这两种方式,然后发 ...

  4. JS 编程艺术

    JS艺术片段剪贴 getFullDate: function (date) { //返回 YYYY年MM月DD日 var year = month = day = ' '; if (isNaN(dat ...

  5. localStorage、sessionStorage和cookie的区别

    本地客户端(浏览器)查看三者信息: HTML4的本地存储:cookie 浏览器的缓存机制提供了可以将用户数据存储在客户端上的方式,可以利用cookie,session等根服务端进行数据交互. 一.co ...

  6. 随机模块 random 函数的调用

    随机模块 random 作用: 用于模拟或生成随机输出的模块. 用法示意: import random as R 函数名 描述 R.random() 返回一个[0, 1) 之间的随机实数 R.unif ...

  7. Spark的Shuffle

    0. Shuffle概述 要理解什么是Shuffle,首先介绍大数据与分布式.我们知道大数据的存储是分布式存储,大数据的计算框架是分布式的计算框架.分布式必然存在数据的交互传输,简言之Shuffle就 ...

  8. Maven新建项目出现 Could not calculate build plan:plugin 错误解决办法

    删除本地.m2仓库中 org.apache.maven.plugins:maven-resources-plugin所在目录. 然后右击项目 Maven->Update Project-> ...

  9. 学习Shell编程

    目录 1 什么是Shell 2 Linux的启动过程 3 怎样编写一个Shell脚本 4 Shell脚本的执行方式 5 内建命令和外部命令的区别 6 管道和重定向 7 变量赋值 8 环境变量配置文件 ...

  10. C语言创建线程以及使用锁进行读写分离

    线程的使用 1.线程的创建 线程的相关操作放在<pthread.h>中. 1.1我们定义一个线程,首先要进行定义一个函数,类似我们创建一个a线程 void *thread_a(void * ...