数据结构实验之链表五:单链表的拆分(SDUT 2120)
#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)的更多相关文章
- 数据结构实验之二叉树五:层序遍历 (SDUT 3344)
#include <bits/stdc++.h> using namespace std; struct node { char data; struct node *lc, *rc; } ...
- 【Java】 大话数据结构(2) 线性表之单链表
本文根据<大话数据结构>一书,实现了Java版的单链表. 每个结点中只包含一个指针域的链表,称为单链表. 单链表的结构如图所示: 单链表与顺序存储结构的对比: 实现程序: package ...
- 数据结构5: 链表(单链表)的基本操作及C语言实现
逻辑结构上一个挨一个的数据,在实际存储时,并没有像顺序表那样也相互紧挨着.恰恰相反,数据随机分布在内存中的各个位置,这种存储结构称为线性表的链式存储. 由于分散存储,为了能够体现出数据元素之间的逻辑关 ...
- SDUT-3402_数据结构实验之排序五:归并求逆序数
数据结构实验之排序五:归并求逆序数 Time Limit: 50 ms Memory Limit: 65536 KiB Problem Description 对于数列a1,a2,a3-中的任意两个数 ...
- SDUT OJ 数据结构实验之图论五:从起始点到目标点的最短步数(BFS)
数据结构实验之图论五:从起始点到目标点的最短步数(BFS) Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss P ...
- SDUT 3344 数据结构实验之二叉树五:层序遍历
数据结构实验之二叉树五:层序遍历 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Description 已知一个按 ...
- [C++]线性链表之单链表
[文档整理系列] 线性链表之单链表 /* 问题描述:线性表____链表_____单链表 @date 2017-3-7 */ #include<iostream> using namespa ...
- 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 给定的一组 ...
随机推荐
- Spring、SpringMVC版本及配置
一.Spring版本 Spring的最新版本是Spring 5.x,Spring 4.x的最后版本是Spring 4.3.x,会维护到2020年(Spring的GitHub主页对此有说明). 二.Sp ...
- 前端工程师应该知道的yarn知识
yarn 是在工作中离不开的工具,但在工作中,很多人基本只会使用 yarn install,而且会手动删除 node-modules,或删除 yarn.lock 文件等不规范操作.本文将从一些基础的知 ...
- mvc控制器返回操作结果封装
实体类 public class AjaxResult { /// <summary> /// 获取 Ajax操作结果类型 /// </summary> public Resu ...
- IOC之MEF学习
MEF原理上很简单,找出有共同接口的导入.导出.然后找到把导出的实例化,赋给导入.说到底MEF就是找到合适的类实例化,把它交给导入.Export 特性可修饰类.字段.属性或方法,而 Import 特性 ...
- phpspider爬虫框架的使用
这几天使用PHP的爬虫框架爬取了一些数据,发现还是挺方便的,先上爬虫框架的文档 phpspider框架文档 使用方法其实在文档中写的很清楚而且在demo中也有使用示例,这里放下我自己的代码做个笔记 & ...
- vue-添加全局扩展方法
1.添加全局方法或者属性,如: vue-custom-element 2.添加全局资源:指令/过滤器/过渡等,如 vue-touch 3.通过全局 mixin 方法添加一些组件选项,如: vue-ro ...
- C#面向对象(抽象类、接口、构造函数、重载、静态方法和静态成员)
1.抽象类 抽象类关键词 abstract (抽象) override (重写) 在父集中用 abstract 表示抽象类,抽象方法,在子集中用 override 改写 抽 ...
- 【python】python _、__、__xx__之间的差别
本文来自 yzl11 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/yzl11/article/details/53792416?utm_source=copy 单下 ...
- 第五章、Django之模型层---单表操作
目录 第五章.Django之模型层---单表操作 一.ORM查询 二.Django测试环境搭建 三.单表查询 1. 增 2. 改 3. 删 4. 查 第五章.Django之模型层---单表操作 一.O ...
- Image Processing and Computer Vision_Review:A survey of recent advances in visual feature detection(Author's Accepted Manuscript)——2014.08
翻译 一项关于视觉特征检测的最新进展概述(作者已被接受的手稿) 和A survey of recent advances in visual feature detection——2014.08内容相 ...