数据结构实验之链表五:单链表的拆分(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 给定的一组 ...
随机推荐
- ACM-ICPC 2017北京
J. Pangu and Stones 大意: 给定$n$堆石子, $(n\le 100)$, 每次操作任选连续的至少$L$堆至多$R$堆合并, 代价为合并石子的总数, 求合并为$1$堆的最少花费. ...
- Windows phone 8 二维码生成与扫描
1. 二维码的生成 二维码生成用到了一个第三方的插件(zxing.wp8.0) 根据指定的信息,生成对应的二维码. 代码很简单: bool falg=tbk.Text==""?fa ...
- VisualSVN Server 安装
1.去官网下载:https://www.visualsvn.com/server/download/ 2.安装: 修改为后: 3.开机自动启动.
- 微信小程序wxs如何使用
新建一个.wxs文件 <!-- 引入.wxs文件 src为相对路径,module指定当前模块的名称 --> <wxs module="filter" src=&q ...
- echarts —— tooltip 鼠标悬浮显示提示框属性
最近一直在使用echarts,当然也被其中的各种属性整的头大,记录一下其中遇到的问题. tooltip:鼠标悬浮时显示的提示框. 今天想要记录的是[自定义提示框的内容],如下图,鼠标悬浮时提示框内显示 ...
- Redis的最常见面试问题
Redis的那些最常见面试问题[转] 1.什么是redis? Redis 是一个基于内存的高性能key-value数据库. 2.Reids的特点 Redis本质上是一个Key-Value类型的内存数据 ...
- axios替换jquery的ajax
<script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.js"></script> <scr ...
- MySQL8.0 caching_sha2_password报错问题
在bin目录下执行mysql -uroot -p123456 登录后执行: use mysql; select host, user, plugin from user; 打印: +--------- ...
- 【uoj#94】【集训队互测2015】胡策的统计(集合幂级数)
题目传送门:http://uoj.ac/problem/94 这是一道集合幂级数的入门题目.我们先考虑求出每个点集的连通生成子图个数,记为$g_S$,再记$h_S$为点集$S$的生成子图个数,容易发现 ...
- 小白老凯,初出茅庐!请多关照!简单分享一些 mysql 数据库的安装操作!请给为大神雅正!
在我们写代码,存储数据时常常会用到各种数据库,如:mysql.access.sql.server.Oracle等等,在这里就说一下mysql数据库的的操作指令! 首先我们了解下如何安装mysql数据库 ...