【SDUT】【链表】2120 - 数据结构实验之链表五:单链表的拆分
Problem Description
Input
第二行依次输入N个整数。
Output
第二行依次输出偶数子链表的所有数据;
第三行依次输出奇数子链表的所有数据。
Sample Input
10 1 3 22 8 15 999 9 44 6 1001
Sample Output
4 6 22 8 44 6 1 3 15 999 9 1001
Hint
Source
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
struct node
{
int data;
struct node *next;
};
int cnt1,cnt2;
//申请空间
struct node *arr_mal(struct node *p)
{
p = (struct node *)malloc(sizeof(struct node));
return p;
}
//创建链表
void arr_create(struct node *head,int n)
{
struct node *p=NULL,*tail=NULL;
tail = head;
while(n--)
{
p = arr_mal(p);
scanf("%d",&p ->data);
tail ->next = p;
tail = tail ->next;
}
}
//输出链表
void arr_prin(struct node *head)
{
struct node *p=NULL;
p = head ->next;
if(p != NULL)
{
printf("%d",p ->data);
p = p ->next;
}
while(p != NULL)
{
printf(" %d",p ->data);
p = p ->next;
}
printf("\n");
}
//拆分
void arr_split(struct node *head1,struct node *head2)
{
struct node *p1=NULL,*p2=NULL,*tail=NULL;
p1 = head1;
p2 = head2;
while(p1 ->next != NULL)
{
)
{
p1 = p1 ->next;
cnt1++;
}
else
{
tail = p1 ->next;
p1 ->next = tail ->next;
tail ->next = NULL;
p2 ->next = tail;
p2 = p2 ->next;
cnt2++;
}
}
}
int main()
{
int n;
cnt1=cnt2=;
struct node *head1=NULL,*head2=NULL;
head1 = arr_mal(head1);
head2 = arr_mal(head2);
scanf("%d",&n);
arr_create(head1,n);
arr_split(head1,head2);
printf("%d %d\n",cnt2,cnt1);
arr_prin(head2);
arr_prin(head1);
;
}
【SDUT】【链表】2120 - 数据结构实验之链表五:单链表的拆分的更多相关文章
- SDUT 3344 数据结构实验之二叉树五:层序遍历
数据结构实验之二叉树五:层序遍历 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Description 已知一个按 ...
- SDUT OJ 数据结构实验之图论五:从起始点到目标点的最短步数(BFS)
数据结构实验之图论五:从起始点到目标点的最短步数(BFS) Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss P ...
- SDUT OJ 数据结构实验之二叉树五:层序遍历
数据结构实验之二叉树五:层序遍历 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descri ...
- SDUT 3402 数据结构实验之排序五:归并求逆序数
数据结构实验之排序五:归并求逆序数 Time Limit: 40MS Memory Limit: 65536KB Submit Statistic Problem Description 对于数列a1 ...
- SDUT 3377 数据结构实验之查找五:平方之哈希表
数据结构实验之查找五:平方之哈希表 Time Limit: 400MS Memory Limit: 65536KB Submit Statistic Problem Description 给定的一组 ...
- SDUT-3402_数据结构实验之排序五:归并求逆序数
数据结构实验之排序五:归并求逆序数 Time Limit: 50 ms Memory Limit: 65536 KiB Problem Description 对于数列a1,a2,a3-中的任意两个数 ...
- php数据结构课程---2、链表(php中 是如何实现单链表的(也就是php中如何实现对象引用的))
php数据结构课程---2.链表(php中 是如何实现单链表的(也就是php中如何实现对象引用的)) 一.总结 一句话总结: php是弱类型语言,变量即可表示数值,也可表示对象:链表节点的数据域的值就 ...
- [C++]数据结构:线性表之(单)链表
一 (单)链表 ADT + Status InitList(LinkList &L) 初始化(单)链表 + void printList(LinkList L) 遍历(单)链表 + int L ...
- SDUT-3377_数据结构实验之查找五:平方之哈希表
数据结构实验之查找五:平方之哈希表 Time Limit: 400 ms Memory Limit: 65536 KiB Problem Description 给定的一组无重复数据的正整数,根据给定 ...
- SDUT-3344_数据结构实验之二叉树五:层序遍历
数据结构实验之二叉树五:层序遍历 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 已知一个按先序输入的字符序列,如abd ...
随机推荐
- 深度强化学习(DQN-Deep Q Network)之应用-Flappy Bird
深度强化学习(DQN-Deep Q Network)之应用-Flappy Bird 本文系作者原创,转载请注明出处:https://www.cnblogs.com/further-further-fu ...
- 小公举-linux的计算器
1.一个方便的linux计算器,精巧而强大bc 2..进行简单的四则运算 3.连续的四则运算 4.大数运算 5.求次幂和余数 6.如果要执行小数计算呢,需要设置scale=number ,number ...
- c++-友元函数和友元类
友元函数 友元函数和友元类(破坏类的封装性) 面向对象编程思想 #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include & ...
- arcgis api 4.x for js 聚合效果图(附源码下载)
前言 关于本篇功能实现用到的 api 涉及类看不懂的,请参照 esri 官网的 arcgis api 4.x for js:esri 官网 api,里面详细的介绍 arcgis api 4.x 各个类 ...
- Android DSelectorBryant 单选滚动选择器
单选滚动选择器.diy丰富.有阻尼效果.简单美观.触摸or点击模式 (Rolling Selector, Diy Rich, Damping Effect, Simple and Beautiful, ...
- Neo4j安装过程详解
在安装neo4j之前,需要安装Java JRE,并配置Java开发环境,然后安装neo4j服务. 一.CentOS下安装 1.下载Neo4j 去官网下载最新的neo4j,选择社区版.地址:https: ...
- 面试连环炮系列(六):Dubbo应用为什么要部署Zookeeper
Dubbo应用为什么要部署Zookeeper? Zookeeper用来注册和发现服务,简单说就是提供端注册接口信息到Zookeeper,调用端在Zookeeper上查找接口对应的服务IP和端口.由于Z ...
- js 从两道面试题加深理解闭包与箭头函数中的this
壹 ❀ 引 在本文之前我已经花了两个篇幅专门介绍了JavaScript中的闭包与this,正好今早地铁上看到了两道面试题,试着做了下发现挺有意思,所以想单独写一篇文章来记录解析过程.若你对于闭包与t ...
- drf请求模块分析
一.drf请求模块 .drf的request是在wsgi的request基础上再次封装 .wsgi的request作为drf的request一个属性:_request .新的request对旧的req ...
- WebShell代码分析溯源(五)
WebShell代码分析溯源(五) 一.一句话变形马样本 <?php $e=$_REQUEST['e'];$arr=array($_POST['POST'],);array_filter($ar ...